Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a boxplot in ggplot requires axis x and y?

Tags:

r

I have a variable ceroonce which is number of schools per county (integers) in 2011. When I plot it with boxplot() it only requires the ceroonce variable. A boxplot is then retrieved in which the y axis is the number of schools and the x axis is... the "factor" ceroonce. But in ggplot, when using geom_boxplot, it requires me to input both x and y axis, but I just want a boxplot of ceroonce. I have tried inputing ceroonce as both the x and y axis. But then a weird boxplot is retrieved in which the y axis is the number of schools but the x axis (which should be the factor variable) is also the number of schools? I am assuming this is very basic statistics, but I am just confused. I am attaching the images hoping this will clarify my question.

This is the code I am using:

ggplot(escuelas, aes(x=ceroonce, y=ceroonce))+geom_boxplot() boxplot(escuelas$ceroonce) 
like image 291
manuelq Avatar asked Jul 31 '14 00:07

manuelq


People also ask

What does Ggplot boxplot represent?

A boxplot summarizes the distribution of a continuous variable and notably displays the median of each group. This post explains how to add the value of the mean for each group with ggplot2. Boxplot Section Boxplot pitfalls. Ggplot2 allows to show the average value of each group using the stat_summary() function.

How do you make a boxplot with a line connecting a value in R?

To create a boxplot with a line Connecting mean values in R we use the overlapping approach of ggplot2. We first create the simple ggplot2 boxplot. Then we take the mean values of data values from the data frame and store them in vector mean.

How do I change the scale of a boxplot in R?

To change the axis scales on a plot in base R, we can use the xlim() and ylim() functions.


1 Answers

ggplot(escuelas, aes(x="ceroonce", y=ceroonce))+geom_boxplot() 

ggplot will interpret the character string "ceroonce" as a vector with the same length as the ceroonce column and it will give the result you're looking for.

like image 198
yeedle Avatar answered Sep 21 '22 01:09

yeedle