set.seed(1234)
wdata = data.frame(
sex = factor(rep(c("F","M"), each=200)),
weight = c(rnorm(200,55), rnorm(200,58)))
head(wdata,4)
hist(wdata$weight, breaks =30, col ="steelblue", frame =FALSE)
library(ggplot2)
theme_set(theme_bw())# Basic plot
ggplot(wdata, aes(x = weight))+
geom_histogram(bins =30)# Change fill color by sex group
ggplot(wdata, aes(x = weight))+
geom_histogram(aes(fill = sex), bins =30, alpha =0.5,
position = position_dodge())+
scale_fill_viridis_d()
library(ggpubr)# Basic plots
gghistogram(wdata, x ="weight", fill ="steelblue", alpha =1)# Change color by sex group
gghistogram(
wdata, x ="weight", color ="sex",
palette = c("#00AFBB","#E7B800"))