【问题标题】:How to make the graph's axis skip fixed values (ggplot2)如何使图形的轴跳过固定值(ggplot2)
【发布时间】:2020-04-21 16:17:49
【问题描述】:

根据下面的例子,如何使图表的 y 轴显示从 25 到 25 的值?

输入代码:

library(ggplot2)

# scatter plot
graph <-ggplot(cars, aes(x = speed, y = dist)) + 
        geom_point() +
        ylim(0,150) +
        xlim(0,30) +
        labs(y = 'y-axis', x = "x-axis") +
        theme_classic()
graph

输入代码的输出:

我阅读了几个教程,但找不到此功能。以下是我阅读的一些教程链接:

https://ggplot2.tidyverse.org/reference/lims.html

https://ggplot2.tidyverse.org/reference/coord_cartesian.html

https://ggplot2.tidyverse.org/reference/lims.html

http://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations

https://ggplot2-book.org/scales.html

[其他一些...]

【问题讨论】:

标签: r ggplot2


【解决方案1】:

我认为您正在寻找 scale_y_continuous:

 # scatter plot
 graph <-ggplot(cars, aes(x = speed, y = dist)) + 
   geom_point() +
   #ylim(0,150) +
   scale_y_continuous(breaks = seq(0, 150, by=25), limits=c(0,150))+
   xlim(0,30) +
   labs(y = 'y-axis', x = "x-axis") +
   theme_classic()
 graph

【讨论】:

    猜你喜欢
    • 2016-12-10
    • 2023-03-28
    • 2023-03-05
    • 2021-10-26
    • 1970-01-01
    • 2020-07-09
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多