r - ggplot x Axis 刻度线标签

标签 r ggplot2 axis

我使用 ggplot2 在 r 中绘制了一个图。代码如下。我的数据集是net_d。比率在 0.5 - 1.0 之间变化。 D2 从 10 变为 1。

p<-ggplot(net_d,aes(Ratio,D2))
p<-p+geom_point()+geom_line()
p<-p+xlab("Multiples of degrees of nodes within community to between community")
p<-p+ylab("Faction of vertices classfied correctly")
#p<-p+scale_x_continuous(breaks=c(seq(10,1,by=-1)))
p<-p+xlim(10,1)+ylim(0.5,1)
p<-p+theme_set(theme_grey())
print(p)

enter image description here

我需要在 x Axis 10 - 1 上有标签,步长为 1。因此,图中的每个点在 x Axis 上都会有一个相应的刻度线。我评论了一个可能的解决方案。但这会将标签反转为 1-10。我需要其他方式。

最佳答案

这应该有效:

library(ggplot2)
coords <- rev(seq(1:10))
vals <- c(rep(1,6),0.98,0.73,0.64,0.66) #approximately extracted from your graph
df <- as.data.frame(rbind(coords,vals))
p <- ggplot(df,aes(x=coords,y=vals))
p <- p + geom_point() + geom_line()
p <- p + xlab("Multiples of degrees of nodes within community to between community")
p <- p + ylab("Faction of vertices classfied correctly")
p <- p + theme_bw()
p <- p + ylim(0.5,1)
p <- p + scale_x_reverse(breaks=c(seq(1,10)))

这是输出: enter image description here

希望这有帮助

关于r - ggplot x Axis 刻度线标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31021827/

相关文章:

r - 脑筋急转弯 R 问题 - 在 R 中解决编程问题

r - 错误 : memory exhausted (limit reached? )//错误 : cannot allocate vector of size 1. 3 Mb

r - 如何使用geom_errorbar在堆叠条形图中堆叠误差条?

vector - 将单位向量转换为四元数

java - 使用 Axis2 附加客户端证书?

r - 获取在 Shiny 中触发的事件?

r - RMarkdown Word文档中,如何让目录稍后出现

r ggplot2 : grouping legend in bar plots

r - ggplot 点中的轻微点描边

python - 将 float 转换为具有固定指数的科学格式