Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when making a simple boxplot with ggplot2

Tags:

r

ggplot2

Using the mpg data in R, I can make a boxplot of 'displ' with

boxplot(mpg$displ)

But when I try to make this simple boxplot with ggplot,

ggplot(data = mpg, aes(displ)) + geom_boxplot()

I get this error;

Error in seq.default(from = best$lmin, to = best$lmax, by = best$lstep) : 'from' must be of length 1
In addition: Warning messages:
1: Continuous x aesthetic -- did you forget aes(group=...)? 
2: In is.na(data$y) :  is.na() applied to non-(list or vector) of type 'NULL'
like image 762
Bell Avatar asked Apr 16 '26 02:04

Bell


1 Answers

ggplot2 requires both an x and y variable of a boxplot. Here is how to make a single boxplot

ggplot(data = mpg, aes(x = "", y = displ)) + 
  geom_boxplot() + 
  theme(axis.title.x = element_blank())
like image 63
Thierry Avatar answered Apr 17 '26 16:04

Thierry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!