[R] How to set colors, axis gap, and free scale in ggplot?

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Tue Feb 22 12:41:16 CET 2022


Hi Luigi

change last two ggplot commands as follows

facet_wrap(. ~ Species, scales="free_y") +
scale_fill_manual(values = c("palegreen4", "orangered3"))

Cheers
Petr

> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Luigi Marongiu
> Sent: Tuesday, February 22, 2022 11:16 AM
> To: r-help <r-help using r-project.org>
> Subject: [R] How to set colors, axis gap, and free scale in ggplot?
> 
> Hello,
> I have a dataframe with 3 columns: the actual measurement (Concentration),
> and two groups (Vitamin and Group). I would like to plot a barplot with
> superimposed a jitterplot, with error bars. I am using facet_grid. All
that I can
> do, but the customization does not work. The customization is as follows:
> I need to supply custom colors to the two classes of the Group column,
then
> have different scales for each panel and give an axis break on the first
panel.
> I made a working example:
> ```
> data("iris")
> bins <- c(1.5)
> iris$Group = findInterval(iris$Petal.Width, 1.5) iris$Group =
> as.factor(iris$Group)
> levels(iris$Group) <- c("Small", "Large") # plot
> library(ggplot2)
> ggplot(iris, aes(Group, Sepal.Length, fill = Group)) +
> geom_bar(position="dodge", stat="summary", fun.y="mean") +
> geom_errorbar(stat="summary", position="dodge", width=0.5) +
> geom_jitter(aes(x=Group), shape=21) + xlab(expression(bold("Plant
species")))
> +
> ylab(expression(bold("Measure"))) +
> # FROM HERE IT DOES NOT WORK
> facet_grid(. ~ Species, scales="free_y") + # THE SCALE IS FIXED FOR ALL
PANELS
> scale_colour_manual(values = c("palegreen4", "orangered3")) # THE COLORS
> ARE AUTOMATIC ```
> 
> I would also like to increase the size of the axis labels and the title
size of the
> panels.
> What is the correct syntax?
> Thanks
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


More information about the R-help mailing list