5

Do any ggplot2 wizards out there know how to make this this look more visually intuitive? Specifically, I'm thinking of annotation at the beginning and end of each time period with the exact date (i.e., for Zhenla the bar would begin with an annotation saying 550 AD, and end with an annotation saying 802AD).

As an aside, I've looked at the annotation documentation and haven't found anything visually appealing. However, knowing ggplot2 and its family of packages as I do, I'm certain there is an attractive option out there.

I'm also curious about any other suggestions you all may have about making this more aesthetically pleasing.

Here's the data:

cambodia = data.frame(Period = c("Funan", "Chenla/Zhenla","Khmer Empire","Dark Ages of Cambodia"),StartDate = c(-500,550,802,1431), EndDate = c(550,802,1431,1863), Color = c("lightblue","lightgreen","lightyellow","pink"))

Note: "Color" does not correspond with the values given- it's more of a placeholder for the graph code:

g2 <- ggplot() +
geom_segment(data=cambodia, aes(x=StartDate, xend=EndDate, y=Period, yend=Period, color=Color), linetype=1, size=2) +
scale_colour_brewer(palette = "Pastel1")+
xlab("Time")+
ylab("Periods of History")+
theme_bw() + theme(panel.grid.minor = element_blank(), panel.grid.major =   element_blank()) + theme(aspect.ratio = .2)
g2 + theme(legend.position="none")
Uwe
  • 41,420
  • 11
  • 90
  • 134
E.O.
  • 351
  • 2
  • 14
  • "More intuitive" isn't a clear programming specification. If this isn't a programming question, then it doesn't belong on Stack Overflow. Maybe try some sort of design forum. – MrFlick Apr 04 '17 at 16:47
  • Here's a suggestion: don't vary the y axis scale. Keep all segments the same height. – yeedle Apr 04 '17 at 17:40

1 Answers1

6

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):

enter image description here

 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))
xraynaud
  • 2,028
  • 19
  • 29
  • Would you mind to include the resulting chart, please? This would help to better value your answer. – Uwe Apr 05 '17 at 05:52
  • I think that looks really nice and you're, right, more intuitive. I was thinking it wouldn't be because it would be too "busy" on the x-axis, but that isn't too busy at all. – E.O. Apr 05 '17 at 07:48