[英]How to combine the line series in two plots rendered in autoplot into a single plot, sharing the same y-axis and with two different x-axes?
[英]How to superimpose 2 plots with same y-axis, but different x-axes in R
有沒有辦法用不同的x軸疊加兩個圖?
我有一個數據集,其中包含患者在服用不同葯物時不同天的收縮壓。 我想按日期創建其SBP的散點圖,並在每種葯物上疊加其SBP的箱線圖。 我分別創建了兩個圖,但無法弄清楚如何將它們組合成一個圖。
library(ggplot2)
library(lubridate)
df <- data.frame(date = c(ymd("2014-09-01") + c(1:5), ymd("2014-09-11") + c(1:5), ymd("2014-09-21") + c(1:5)), sbp1 = round(runif(n=15, min=130, max=200)), group = c(rep("A",5), rep("B",5), rep("C", 5)))
p1 <- ggplot(df, aes(x=date, y=sbp1)) + geom_point(aes(color = group))
p2 <- ggplot(df, aes(x=group, y=sbp1)) + geom_boxplot(aes(x=group, y = sbp1))
p1
p2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.