将图叠加成一个图

时间:2019-04-01 10:21:55

标签: r ggplot2 dplyr

我想将两个图合并为一个图: 当我尝试下面的代码时:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.CheckoutScreen">


<!-- This is an example of how my view should look like -->

<CheckBox
    android:id="@+id/favourite_checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/textView4"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/textView4" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:text="T"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="@+id/textView4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/textView4" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:text="Title"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@+id/textView5"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.383" />

我收到此消息错误:

data_df <- df%>%
   filter(!is.na(LayerName)) %>%
   dplyr::select(LayerName, A,B) %>%
   group_by(LayerName) %>%
   dplyr::summarise(lower=min(A),upper=max(A),Mean=mean(A),
                lower_out=min(B),upper_out=max(B),Mean_out=mean(B)) 

  c<-ggplot(data = data_df, mapping = aes(x = LayerName, y = Mean)) +
   geom_pointrange(mapping = aes(ymin = lower, ymax = upper),color = "red")


   r<-c+ggplot(data = data_df, mapping = aes(x = LayerName, y = Mean_out)) +
   geom_pointrange(mapping = aes(ymin = lower_out, ymax = upper_out),color = "blue")+
   theme_bw()
   ggplotly(r)

1 个答案:

答案 0 :(得分:1)

您可以添加额外的图层,但要避免两次使用ggplot()。因此,像这样更改r的分配可能会起作用:

   r<-c +
   geom_pointrange(mapping = aes(y = Mean_out, ymin = lower_out, ymax = upper_out), color = "blue") +
   theme_bw()