I am working on a project where I need to combine data from two different data frames into a single plot using ggplot2 in R. I was wondering how I can efficiently achieve this, assigning specific features to each dataset in the plot.
我有两个数据框架,每个框架都有不同的变量。 我愿在单一图表中为df1和df2铺设地块,同时为每个数据集提供彩色、形状和标签等定制地块。
我希望我的阴谋能够突出两个背景信息,一个是纯洁的,另一个是绿色的,另一个是每个斜体的roid。 这些计算方法是利用<代码>stat_ellipse和df2
的数据生成的。 就地而言,我想到df1
>中的要点,但如以下文字所述,这些要点有色梯度:
# Create data frame df1
df1 <- data.frame(
x = c(1, 2, 3, 4, 5),
y = c(2, 4, 3, 6, 5),
color = runif(5, 0, 1))
# Create data frame df2
df2 <- data.frame(
x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
y = rnorm(10),
group = rep(c( A , B ), each = 5))
为了造就这块土地,我不敢确定该信息是否应当直接输入到综合法典中,或者说应该直接输入地球点和静态。 无论是哪种方式,我都无法保证如何分别调整每一块地的颜色。
plotGG <- ggplot() +
stat_ellipse(data = df2, aes(x = x, y = y, color = group)) + #i want those ellipses purple and green
geom_point(data = df1, aes(x = x, y = y, color = color), size = 3) +
scale_color_gradient2(midpoint=0.5,low="#ba1414ff",mid = "#f3f3b9ff",high="#369121ff") #this is the color pallete that i want for the geom_points
I have progressed to this point, but it generates errors one way or another. Thank you in advance!