ggplot2: Creating a visually intuitive timeline in R [closed]

亡梦爱人 提交于 2019-12-06 04:03:49

It's not really a programming question, but I think it's still interesting as it shows how to play with ggplot possibilities. I would put all segments at the same height, and use the x-axis to show the main dates you're interested in (I'm not sure about where to place the text, though):

 ggplot(data=cambodia) +
  geom_segment(aes(x=StartDate, xend=EndDate, y=0., yend=0., color=Period) , linetype=1, size=4) +
  scale_colour_brewer(palette = "Pastel1")+
  scale_y_continuous(limits=c(0,0.5))+
  scale_x_continuous(limits=c(-500,2000),  breaks= c(seq(0,2000,by=1000), cambodia$StartDate, cambodia$EndDate[4]))+
  xlab("Time")+
  ylab("Periods of History")+
  theme_bw() + theme(panel.grid.minor = element_blank(), panel.grid.major =   element_blank(), axis.title.y=element_blank(),axis.text.y=element_blank(),  axis.ticks.y=element_blank()) +
  theme(aspect.ratio = .2)+
  theme(legend.position="none") + 
  geom_text(aes(x=StartDate-100 + (EndDate- StartDate)/2,y=0.05,label=Period,angle=25,hjust=0))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!