特定位置的背景色ggplot2 boxplot

时间:2019-03-06 17:37:15

标签: r ggplot2 colors

我有以下代码使用boxplot绘制一些数据。我想知道如何在图形中绘制一些背景色。例如,如果我可以在第1组和第2组之间绘制灰色背景,而在第16组和第18组之间绘制深灰色背景,那将非常好。我非常感谢您的帮助。问候。

dados <- read.table(text =  'subj var   time    group 
1:  0.9995127   PT  0
2:  0.9994366   PT  0
3:  0.9997657   PT  0
4:  0.9996991   PT  0
5:  0.9938514   T1  1
6:  0.9985952   T1  1
7:  0.9989975   T1  1
8:  0.9988476   T1  1
9:  0.9884567   T2  2
10: 0.998   T2  2
11: 0.9900545   T2  2
12: 0.9973228   T2  2
65: 0.9818935   POT1    16
66: 0.9196845   POT1    16
67: 0.8605142   POT1    16
68: 0.8620914   POT1    16
69: 0.9878192   POT2    17
70: 0.9826672   POT2    17
71: 0.9640381   POT2    17
72: 0.8976091   POT2    17
73: 0.9907579   POT3    18
74: 0.9922122   POT3    18
75: 0.9808981   POT3    18
76: 0.8988121   POT3    18', header = T)
library(ggplot2)
library(dplyr)
dados$group <- as.factor(dados$group)
head (dados)
p<-ggplot(dados, aes(x=group, y=var)) + geom_boxplot()
p + scale_x_discrete(breaks=c("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),labels=c("PT","T01", "T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","POT1","POT2","POT3","POT4","POT5","POT6","POT7"))

1 个答案:

答案 0 :(得分:0)

这与您要寻找的东西很近吗?

(假设您已经完成了上面的dados数据帧后处理)

<fragment
        android:name="MapFragment"
        android:tag="map_fragment_tag"
        android:layout_marginBottom="50dp" />

<LinearLayout
        android:orientation="vertical"
        app:behavior_peekHeight="50dp"
        app:layout_behavior="MyCustomBottomSheetBehavior">

    <View
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#ff0000">

    <MyNoClickableFrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!-- Content is here -->

    </NoClickableFrameLayout>
</LinearLayout>

尽管较深的灰色至少在这种情况下会损害晶须的可见性。