Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The base graphics can nicely plot a boxplot using a simple command

data(mtcars)
boxplot(mtcars$mpg)

enter image description here

But qplot requires y axis. How can I achieve with qplot the same like base graphics boxplot and not get this error?

qplot(mtcars$mpg,geom='boxplot')
Error: stat_boxplot requires the following missing aesthetics: y
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to provide some dummy value to x. theme() elements are used to remove x axis title and ticks.

ggplot(mtcars,aes(x=factor(0),mpg))+geom_boxplot()+
   theme(axis.title.x=element_blank(),
    axis.text.x=element_blank(),
    axis.ticks.x=element_blank())

Or using qplot() function:

qplot(factor(0),mpg,data=mtcars,geom='boxplot')

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...