I like the ability to easily separate data into different series using ggboxplot
. The x-axis labels can remain easy to read while a 2nd categorical variable is shown via adjacent colored series.
p <- ggboxplot(df_dummy, x="Trt_Amend", y="Carbon_percent", color="Trt_CC",
palette=c("red", "blue"),
main="Great Plot Title",
xlab="1st Categorical Variable",
ylab="Continuous Variable") +
theme(plot.title = element_text(hjust = 0.5)) + # Center plot title.
grids(linetype="dashed") +
border("black")
ggpar(p, x.text.angle=45,
legend.title="2nd Categorical Variable",
font.main=14,
ylim=c(0.6, 1.6))
Using boxplots isn't always appropriate though, like when each group has a low number of observations (< 20). Can someone help me figure out how to do this in a ggplot
using geom_point
?
# How to separate colored series using geom_point?
ggplot(df_dummy, aes(Trt_Amend, Carbon_percent, color=Trt_CC)) +
geom_point()
Thanks for reading!
The first step would be to dodge your points using
position = position_dodge(.75)
or to add some jitter usingposition_jitterdodge()
as I do below. The rest of the code is - similar toggpubr:: ggboxplot
- just styling.Using some fake random example data:
EDIT You could use two
stat_summary
layers to add errorbars and the mean: