The base graphics can nicely plot a boxplot using a simple command
data(mtcars)
boxplot(mtcars$mpg)
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
Boxplots can be created for individual variables or for variables by group. The format is boxplot(x, data=), where x is a formula and data= denotes the data frame providing the data.
To convert this to Horizontal Boxplot add coord_flip() in the boxplot code, and rest remains the same as above. Example: R.
Box plots are composed of an x-axis and a y-axis. The x-axis assigns one box for each Category or Numeric field variable. The y-axis is used to measure the minimum, first quartile, median, third quartile, and maximum value in a set of numbers. You can use box plots to visualize one or many distributions.
The common way to put labels on the axes of a plot is by using the arguments xlab and ylab. As you can see from the image above, the label on the Y axis is place very well and we can keep it. On the other hand, the label on the X axis is drawn right below the stations names and it does not look good.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With