Home > Enterprise >  Boxplot (ggplot2) not working as expected
Boxplot (ggplot2) not working as expected

Time:12-07

I'm trying to plot a simple boxplot where I get 15 boxplots for respondents age of 15 "Cadernos" (15 surveys, surveys A, B, C .. to O). But that's not working as expected. I have already tried to switch places to the "Cadernos" (surveys) and "Idade" (age) variables. Any idea? What I expected was 15 boxplots in the vertical axis.

The code I'm using is the follow:

library(ggplot2)

select_base %>% 
  ggplot(aes(Idade,Caderno))  
  geom_boxplot()  

the plot I get is the following:

enter image description here

CodePudding user response:

I'm not sure that you did not provide your data, but you may try

select_base %>% 
  ggplot(aes(x = Caderno, y = Idade, group = Caderno))  
  geom_boxplot()  

For example using data dummy it will be like plot below

dummy <- data.frame(
  x = rnorm(50),
  y = rep(c("a","b","c","d","e"),10)
)
dummy %>%
  ggplot(aes(x = y,y = x,  group = y))  
  geom_boxplot()

enter image description here

  • Related