【发布时间】:2019-08-03 01:10:40
【问题描述】:
我正在努力使我的图表看起来尽可能好。我已经尝试了几件事。 我想让箭头穿过线条的一半。而且我总是看到 ggplot 图表上的颜色看起来也更好,但我不知道该去哪里。 对以下/建议的任何更改都会很棒。
x<-c(2,3,3,4,4,5,5)
w<-c(168,108,158,45,114,81,110)
w<-as.data.frame(w)
x<-as.data.frame(x)
wts<-data.frame(x,w)
h <- ggplot(data=wts, aes(x,w, label="w"))
h <- h + geom_point(colour="blue")
h <- h + labs(title="Breaches",x = "Quarter", y= "Number of Breaches")
h<-h + theme_bw()
h
h<-h +
geom_line(data=wts[c(1,2),], colour="green",arrow=arrow())+
geom_line(data=wts[c(3,4),], color="green",arrow=arrow())+
geom_line(data=wts[c(5,6),], color="green",arrow=arrow())+
geom_line(data=wts[c(2,3),], color="red",arrow=arrow())+
geom_line(data=wts[c(4,5),], color="red",arrow=arrow())+
geom_line(data=wts[c(6,7),], color="red",arrow=arrow())
# h<-h+
# geom_point(data=wts[c(8,9,10),], color="red")
h
txt2<- c("60","","","","","","")
txt3<- c("","","113","","","","")
txt4<- c("","","","","","33","")
txt5<- c("","50","","","","","")
txt6<- c("","","","69","","","")
txt7<- c("","","","","","","29")
txt7a<- c("168","108","158","45","114","81","110")
h<-h+ geom_text(aes(label=txt2),position = position_nudge(x=0.5,y = -30))
h<-h+ geom_text(aes(label=txt3),position = position_nudge(x=0.4,y = -30))
h<-h+ geom_text(aes(label=txt4),position = position_nudge(x=-0.45,y = 20))
h<-h+ geom_text(aes(label=txt5),position = position_nudge(x=0.1,y = 15))
h<-h+ geom_text(aes(label=txt6),position = position_nudge(x=0.1,y = 30))
h<-h+ geom_text(aes(label=txt7),position = position_nudge(x=0.1,y = -10))
h<-h+ geom_text(aes(label=txt7),position = position_nudge(x=0.1,y = -10))
h<-h+ geom_text(aes(label=txt7a),position = position_nudge(x=0.1,y = 0))
h<-h + ylim(25,170)
h<-h+
scale_x_continuous(breaks=c(2,3,4,5),
labels=c("Q218","Q318", "Q418", "Q119"))
h
【问题讨论】:
-
看看ggplot2 extensions,也许是
ggforce。有很多东西可以用来制作很棒的图表。不幸的是,从来没有看到中途带箭头的图表。我有兴趣! -
画两段,一段没有箭头,一段有箭头的一半。只需谷歌
r colors即可找到所有颜色的概览。例如。在许多情况下,firebrick比red要好得多。
标签: r ggplot2 plot graph rstudio