[R] Axis Breaks with ggplot2
John Kane
jrkrideau at inbox.com
Mon Oct 22 14:12:38 CEST 2012
Not in ggplot2 as far as I know. As Jim Lemon says the plotrix package should handle this.
An alternative that probably gives better data interpretation might be to use facet.grid() or perhaps facet_wrap() in ggplot2.
Crude example
library(ggplot2)
xx <- data.frame(aa = c(10, 12, 15, 55, 65), cc <- 1:5, bb = c("a","a","a","b","b"))
str(xx)
gbar <- ggplot(xx, aes(cc, aa, fill= cc)) + geom_bar(stat="identity")
gbar + facet_grid(bb ~ .)
John Kane
Kingston ON Canada
> -----Original Message-----
> From: patze003 at umn.edu
> Sent: Fri, 19 Oct 2012 09:50:49 -0500
> To: r-help at r-project.org
> Subject: [R] Axis Breaks with ggplot2
>
> R-help -
>
> I'm trying to create axis breaks similar to this :
> http://www.r-bloggers.com/wp-content/uploads/2010/08/bar-chart-natural-axis-split1.png
> .
>
> Is there a way to do this in R? Here's my code thus far:
>
> structure(list(condition = structure(c(2L, 1L, 3L), .Label = c("con",
> "exp", "unedit"), class = "factor"), trial.avg = c(4.04583333333333,
> 4.33541666666667, 4.61875), trial.sd = c(0.928718367573187,
> 0.851822141963017,
> 1.03502368980692), s.e. = c(0.0232179591893297, 0.0212955535490754,
> 0.163651614601074), N = c(40, 40, 40), condition2 = structure(1:3, .Label
> =
> c("Interaction Censured",
> "Control Censured", "Uncensured"), class = "factor")), .Names =
> c("condition",
> "trial.avg", "trial.sd", "s.e.", "N", "condition2"), row.names = c(NA,
> -3L), class = "data.frame")
>
> library(ggplot2)
> none <- theme_blank()
> err1$condition <- as.factor(err1$condition)
> censorA <- ggplot() + geom_bar(aes(y = trial.avg, x =
> as.factor(condition2), fill = as.factor(condition2), position = "dodge"),
> data = err1)
>
> censorB <- censorA + geom_errorbar(aes(x = err1$condition2, ymin =
> (err1$trial.avg-(err1$trial.sd/sqrt(40))), ymax = (err1$trial.avg+(err1$
> trial.sd/sqrt(40))), data = err1, width = .4))
>
> censorC <- censorB + opts(panel.background = none) + opts(panel.border =
> none) + opts(panel.grid.minor = none) + opts(panel.grid.major = none) +
> opts(axis.line = theme_segment(colour = "grey35")) + opts(background.fill
> =
> none)
>
>
> censorC + scale_y_continuous(limits = c(0,7), expand = c(0,0), 'Rating')
> +
> opts(legend.position = "none")
>
> Best,
>
> --
> Edward H. Patzelt
> Research Assistant ? TRiCAM Lab
> University of Minnesota ? Psychology/Psychiatry
> VA Medical Center
> S355 Elliot Hall: 612-626-0072
> www.psych.umn.edu/research/tricam
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails
More information about the R-help
mailing list