如何在R中的散点图上生成特定数量的Y轴记号
下面是我的代码,我只希望Y轴的刻度以5%的增量增加,因为刻度太多,因为它们对应于每个绘图如何在R中的散点图上生成特定数量的Y轴记号,r,ggplot2,scatter-plot,R,Ggplot2,Scatter Plot,下面是我的代码,我只希望Y轴的刻度以5%的增量增加,因为刻度太多,因为它们对应于每个绘图 library(ggplot2) ggplot(data = data, aes(x = X, y = Y, label = Label)) + geom_point() + scale_colour_manual(values = c("steelblue4", "chartreuse4", "gold", "firebrick2")) + geom_text(aes(color = G
library(ggplot2)
ggplot(data = data, aes(x = X, y = Y, label = Label)) +
geom_point() +
scale_colour_manual(values = c("steelblue4", "chartreuse4", "gold", "firebrick2")) +
geom_text(aes(color = Goal), position = "jitter", hjust=0.5, vjust=1.1, size = 2.3) +
labs(title = "Google", x = "Correlation Coefficient", y = "Top-Box %")
尝试将此图层添加到ggplot:
scale_y_continuous(breaks=seq(min(data$Y),max(data$Y),(max(data$Y)-min(data$Y))/20))
breaks=
参数采用一个向量,允许您手动指定中断。要在data$Y
中从最低值到最高值获得20个等距值,seq
函数非常方便。您还可以将seq()
函数包装为round()
函数,以清除max()-min()/20
可能产生的混乱数字。我尝试过,我得到了“Error in Summary.factor(c(14L,17L,16L,12L,15L,11L,7L,14L,4L,15L,:min对factors没有意义”@用户3638007这是因为您的数据Y是因子
而不是数值
。如果您将数据$Y
转换为数值(数据$Y=as.numeric(数据$Y)
)然后再次运行绘图它应该会工作。@user3638007很抱歉,我不太理解你的问题。你的数据$Y
数据到底是什么样子的?你说的“保持百分比”是什么意思?尝试添加标签=百分比
作为缩放Y连续
层的参数:缩放Y连续(breaks=seq(min(data$Y)、max(data$Y)、(max(data$Y)-min(data$Y))/20、labels=percent)
。应该可以了!@user3638007您尝试过我上面提到的百分比格式解决方案了吗?