Boxplot is an R function that represents a numeric vector of data that is split in several groups.

When the number of points in each group is highly different, it can be great to represent it using the width of the box.

First calculate the proportion of each level using the table function. Using these proportions will make the box twice bigger if a level is twice more represented. Then give these proportions to the width function when you call Boxplot.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#Creating data names=c(rep("A", 20) , rep("B", 8) , rep("C", 30), rep("D", 80)) value=c( sample(2:5, 20 , replace=T) , sample(4:10, 8 , replace=T), sample(1:7, 30 , replace=T), sample(3:8, 80 , replace=T) ) data=data.frame(names,value) # Calculate proportion of each level proportion=table(data$names)/nrow(data) #Draw the boxplot, with the width proportionnal to the occurence ! boxplot(data$value ~ data$names , width=proportion , col=c("orange" , "seagreen")) |

*Not really what you are looking for ? Make a new search !*

## Leave a Reply