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

后端 未结 3 1577
死守一世寂寞
死守一世寂寞 2021-02-02 10:27

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

相关标签:
3条回答
  • 2021-02-02 10:54
    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.

    0 讨论(0)
  • 2021-02-02 11:11

    This could work for you:

    ggplot(escuelas, aes(x= "", y=ceroncee)) + geom_boxplot()
    
    0 讨论(0)
  • 2021-02-02 11:14

    There are no fancy statistics happening here. boxplot is simply assuming that since you've given it a single vector, that you want a single box in your boxplot. ggplot and geom_histogram simply don't make that assumption.

    If you want a bit less typing, you can do this:

    qplot(y=escuelas$ceroonce, x= 1, geom = "boxplot")
    

    ggplot2 will automatically create a vector of 1s equal in length to the length of escuelas$ceroonce

    0 讨论(0)
提交回复
热议问题