How to create geom_boxplot with large amount of continuous x-variables

后端 未结 2 1753
刺人心
刺人心 2020-12-29 06:48

I have a data frame which contains x-axis numeric bins and continuous y-axis data across multiple categories. Initially, I created a boxplot by making the x-axis bins \"fact

2条回答
  •  长情又很酷
    2020-12-29 07:01

    Here is a way using the original data you posted on Google - which actually was much more helpful, IMO.

    ggplot(df, aes(x=CH, y=value,group=CH))+
      geom_boxplot(notch=FALSE, outlier.shape=NA, fill="red", alpha=0.2)+
      scale_x_log10()
    

    So, as @BenBolker said before he deleted his answer(??), you should leave the x-variable (CH) as numeric, and set group=CH in the call to aes(...).

    With your real data there is another problem though. Your CH is more or less logarithmically spaced, so there are about as many points < 1 as there are between 1 - 10, etc. ggplot wants to make the boxes all the same size, so with a linear x-axis the box width is smaller than the line width, and you don't see the boxes at all. Changing the x-axis to a logarithmic scale fixes that, more or less.

提交回复
热议问题