r - Getting a 2x2 facet_grid with varying scales -
i have data in nice format ideally plot on 2x2 frame, each individual plot having it's own x , y scales. here's code using of now:
p <- ggplot(data=temp,aes(x=variable,y=value,group=custno,color=cluster)) + geom_path(alpha=0.4) + theme_bw() + theme(legend.title=element_blank(),axis.text.y=element_text(hjust=0, angle=0), axis.text.x = element_text(hjust=1, angle=45),plot.title=element_text(size=20)) + ylab('revenue') + xlab('') + ggtitle('') + scale_color_manual(values=c('#66c2a5','#fc8d62','#8da0cb','#e78ac3')) + facet_grid(.~cluster,scales='free',space='free') p
here's plot get:
i want have 2x2 grid separate scales, category 3
little more glorified , differences more pronounced.
here's sample data
custno variable value cluster 100 month1 169.15 3 250 month1 4012.15 1 303 month1 2731.08 1 312 month1 890.40 2 337 month1 1133.40 3 100 month2 169.15 3 250 month2 4012.15 1 303 month2 2731.08 1 312 month2 890.40 2 337 month2 1133.40 3 100 month3 169.15 3 250 month3 4012.15 1 303 month3 2731.08 1 312 month3 890.40 2 337 month3 1133.40 3 100 month4 169.15 3 250 month4 4012.15 1 303 month4 2731.08 1 312 month4 890.40 2 337 month4 1133.40 3 100 month5 169.15 3 250 month5 4012.15 1 303 month5 2731.08 1 312 month5 890.40 2 337 month5 1133.40 3 100 month6 169.15 3 250 month6 4012.15 1 303 month6 2731.08 1 312 month6 890.40 2 337 month6 1133.40 3
any appreciated.
you want replace
facet_grid(.~cluster,scales='free',space='free')
with
facet_wrap(~ cluster, scales = 'free', space = 'free', nrow = 2)
the difference between facet_wrap
, facet_grid
facet wrap can "line break" within single variable. facet_grid
made grid of plots 1 (or more) variables defining columns , different variable(s) defining rows, such line breaks don't make sense.
Comments
Post a Comment