First question I've asked on stack and I'm pretty new to R, so please pardon any etiquette offenses. I'm plotting 2 stacked area charts using ggplot2. The data is wait events from an Oracle database. It's a performance tuning chart. I have several questions.
- The two plots below do not line-up correctly, most likely due to the width of text in the legend. Is there an easy solution to this?
- The two plots are really correlated, where the top plot shows wait classes like "CPU" and "User I/O" and the bottom plot shows the details of the specific wait events in those classes. I'd like the colors in the bottom to be based on the wait class, the same as the top, just different shades of that color for the specific events. I'm also open to other options if you don't like the concept. It's a lot of information to convey. I've limited the number of events to 12 to fit in the color scheme, but there are more if it can work.
- I'd like to either show more granular time ticks on the X, or perhaps even shade the off-business hours (6pm-8am) gray just to convey a better sense of time of day.
- Are there any color schemes with more than 12 colors people commonly use? Looked through brewer and this is the max. I know I could create my own, just curious.
Here's my code:
library(ggplot2)
library(RColorBrewer)
library(gridExtra)
DF_AAS <- read.csv('http://dl.dropbox.com/u/4131944/Permanent/R-Questions/AAS-Plot/DATA_FRAME_AAS.csv', head=TRUE,sep=",",stringsAsFactors=TRUE)
DF_AAS <- within(DF_AAS, snap_time <- as.POSIXlt(snap_times2,
format = "%Y-%m-%d %H:%M:%S"))
DF_AAS[c('snap_times2')] <- NULL
DF_AAS_EVENT <- read.csv('http://dl.dropbox.com/u/4131944/Permanent/R-Questions/AAS-Plot/DF_AAS_EVENT.csv', head=TRUE,sep=",",stringsAsFactors=TRUE)
DF_AAS_EVENT <- within(DF_AAS_EVENT, snap_time <- as.POSIXlt(snap_times2,
format = "%Y-%m-%d %H:%M:%S"))
DF_AAS_EVENT[c('snap_times2')] <- NULL
plot_aas_wait_class <- ggplot()+
geom_area(data=DF_AAS, aes(x = snap_time, y = aas,
fill = wait_class),stat = "identity", position = "stack",alpha=.9)+
scale_fill_brewer(palette="Paired",breaks = sort(levels(DF_AAS$wait_class)))+
scale_y_continuous(breaks = seq(0, max(DF_AAS$aas)+(max(DF_AAS$aas)*.2), 5))+
opts(panel.background = theme_rect(colour = "#aaaaaa"))
plot_aas_event <- ggplot()+
geom_area(data=DF_AAS_EVENT, aes(x = snap_time, y = aas,
fill = wait_class_event),stat = "identity", position = "stack")+
scale_fill_brewer(palette="Paired",breaks = DF_AAS_EVENT$wait_class_event)+
scale_y_continuous(breaks = seq(0, max(DF_AAS_EVENT$aas)+(max(DF_AAS_EVENT$aas)*.2), 5))+
opts( panel.background = theme_rect(colour = "#aaaaaa"))
grid.arrange(arrangeGrob(plot_aas_wait_class, plot_aas_event),heights=c(1/2,1/2),ncol=1)