基于下面的示例,如何使图形的 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
Run Code Online (Sandbox Code Playgroud)
我读了几个教程,我找不到这个功能。以下是我阅读的一些教程链接:
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
[其他一些...]
小智 5
我认为您正在寻找 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
Run Code Online (Sandbox Code Playgroud)