# Data
df <- data.frame(dose=c("D0.5", "D1", "D2"),
len=c(4.2, 10, 29.5))
print(df)
# Basic plot with label outsite
# +++++++++++++++++++++++++++
ggbarplot(df, x = "dose", y = "len",
label = TRUE, label.pos = "out")
# Change width
ggbarplot(df, x = "dose", y = "len", width = 0.5)
# Change the plot orientation: horizontal
ggbarplot(df, "dose", "len", orientation = "horiz")
# Change the default order of items
ggbarplot(df, "dose", "len",
order = c("D2", "D1", "D0.5"))
# Change colors
# +++++++++++++++++++++++++++
# Change fill and outline color
# add labels inside bars
ggbarplot(df, "dose", "len",
fill = "steelblue", color = "steelblue",
label = TRUE, lab.pos = "in", lab.col = "white")
# Change colors by groups: dose
# Use custom color palette
ggbarplot(df, "dose", "len", color = "dose",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
# Change fill and outline colors by groups
ggbarplot(df, "dose", "len",
fill = "dose", color = "dose",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
# Plot with multiple groups
# +++++++++++++++++++++
# Create some data
df2 <- data.frame(supp=rep(c("VC", "OJ"), each=3),
dose=rep(c("D0.5", "D1", "D2"),2),
len=c(6.8, 15, 33, 4.2, 10, 29.5))
print(df2)
# Plot "len" by "dose" and change color by a second group: "supp"
# Add labels inside bars
ggbarplot(df2, "dose", "len",
fill = "supp", color = "supp", palette = "Paired",
label = TRUE, lab.col = "white", lab.pos = "in")
# Change position: Interleaved (dodged) bar plot
ggbarplot(df2, "dose", "len",
fill = "supp", color = "supp", palette = "Paired",
label = TRUE,
position = position_dodge(0.9))
# Add points and errors
# ++++++++++++++++++++++++++
# Data: ToothGrowth data set we'll be used.
df3 <- ToothGrowth
head(df3, 10)
# It can be seen that for each group we have
# different values
ggbarplot(df3, x = "dose", y = "len")
# Visualize the mean of each group
ggbarplot(df3, x = "dose", y = "len",
add = "mean")
# Add error bars: mean_se
# (other values include: mean_sd, mean_ci, median_iqr, ....)
# Add labels
ggbarplot(df3, x = "dose", y = "len",
add = "mean_se", label = TRUE, lab.vjust = -1.6)
# Use only "upper_errorbar"
ggbarplot(df3, x = "dose", y = "len",
add = "mean_se", error.plot = "upper_errorbar")
# Change error.plot to "pointrange"
ggbarplot(df3, x = "dose", y = "len",
add = "mean_se", error.plot = "pointrange")
# Add jitter points and errors (mean_se)
ggbarplot(df3, x = "dose", y = "len",
add = c("mean_se", "jitter"))
# Add dot and errors (mean_se)
ggbarplot(df3, x = "dose", y = "len",
add = c("mean_se", "dotplot"))
# Multiple groups with error bars and jitter point
ggbarplot(df3, x = "dose", y = "len", color = "supp",
add = "mean_se", palette = c("#00AFBB", "#E7B800"),
position = position_dodge())
Run the code above in your browser using DataLab