如何在 R 中使用 ggplot2 设置 Y 轴刻度标记?
使用 ggplot2 的 Y 轴刻度标记的默认值由 R 使用所提供的数据获取,但我们可以通过使用 ggplot2 包的 scale_y_continuous 函数进行设置。例如,如果我们希望以 1 的间隔从 1 到 10 拥有值,那么我们可以使用 scale_y_continuous(breaks=seq(1,10,by=1))。
示例
Consider the below data frame: x<-rpois(20,5) y<-rpois(20,2) df<-data.frame(x,y) df
输出
x y 1 8 1 2 4 3 3 1 1 4 4 1 5 3 2 6 3 6 7 6 4 8 3 3 9 7 1 10 4 1 11 5 1 12 6 3 13 3 1 14 6 3 15 8 2 16 0 2 17 8 1 18 5 0 19 4 1 20 4 3
加载 ggplot2 包并创建 x 和 y 之间的点图 −
示例
library(ggplot2) ggplot(df,aes(x,y))+geom_point()
输出

创建 Y 轴刻度标记差异为 1 的点图 −
示例
ggplot(df,aes(x,y))+geom_point()+scale_y_continuous(breaks=seq(1,10,by=1))
输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP