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

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Tue Feb 22 11:15:51 CET 2022


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



More information about the R-help mailing list