Program 13

Author

Atharsh K

Write an R program to create multiple data plots for grouped data,comparing the distribution of variable across different categories using ggplot 2’s position-function.

Step 1:

library(ggplot2)

Step 2:

data(ToothGrowth)
ToothGrowth$dose<-as.factor(ToothGrowth$dose)
head(ToothGrowth)
   len supp dose
1  4.2   VC  0.5
2 11.5   VC  0.5
3  7.3   VC  0.5
4  5.8   VC  0.5
5  6.4   VC  0.5
6 10.0   VC  0.5

Step 3:

ggplot(ToothGrowth,aes(x=dose,y=len,fill = supp))+
  geom_dotplot(
    binaxis = 'y',
    stackdir = 'centerwhole',
    position = position_dodge(width=0.8),
    dotsize = 0.6,
    binwidth = 1.5
  ) +
  labs(title="Distribution of ToothGrowth",x="Dose",y="Len")+
  theme_minimal()