繁体   English   中英

ggplot x 轴刻度线标签

[英]ggplot x-axis tick marks labels

我使用 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)

在此处输入图片说明

我需要在 x 轴 10 - 1 中有标签,步长为 1。因此图中的每个点都会在 x 轴上有一个相应的刻度线。 我评论了一个可能的解决方案。 但这将标签反转为 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)))

这是输出:在此处输入图片说明

希望这可以帮助

您可以使用scale_x_reverse

#using the cars database
p<-ggplot(cars,aes(speed,dist))
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_reverse(breaks=c(seq(1,25,by=1)))
p<-p+ylim(1,100)
p<-p+theme_set(theme_grey())
print(p)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM