如何在一个图中有多个颜色刻度 [英] How to have multiple color scales into one plot R
问题描述
我有三个数据系列,包括:
I have three data series which are composed of :
- X(float)
- Y(float)
- S(float)
- 类别(离散值)
- X (float)
- Y (float)
- S (float)
- Class (discrete values)
所有三个数据系列共享相同的X坐标,但每个其他组件与每个其他数据系列不同。通过对我的三个数据系列(g的库ggpplot2)使用一个geom_point(),我想根据它具体的 S $ c $用一个颜色标度绘制每个数据系列c>如下:
All three data series are sharing the same X coordinate but every other component is different from each other data series. By using one geom_point() for each of my three data series (the library ggpplot2 in R) I would like to plot each of the data series with a color scale according to it specific S
as follow :
ggplot(data, aes(x=X)) + geom_point(aes(y=Y, colour=S, shape=Class))
如果我只使用一个数据系列,问题是如果我使用自己的 Y
和定义三个
geom_points(),它们都有相同的颜色标度,这是有点混乱的情节。
This works if I am using only one data series. The problem is that if I define three geom_points()
as specified using their own Y
and S
, they all have the same color scale and this is a bit confusing on the plot.
由于我已经在使用形状来区分类
,我真的很喜欢有一个特定的颜色对于我的每个数据系列都有自己的颜色渐变。
As I am already using the shapes to distinguish between the Class
es I would really enjoy to have a specific color with its own color gradient for each of my data series .
例如:
- 从深蓝色到浅蓝色数据系列1
- 数据系列2从暗红色到浅红色
- 数据系列3从深黄色变为浅黄色3
我环顾四周,但我没有找到满足我需求的东西。有些评论说,使用ggplot2它不可能有多个颜色标度每个剧情...是真的吗?
I looked around but I haven't found anything satisfying my needs. Some comments where saying that using ggplot2 it is not possible to have more than one color scale per plot... Is it true ?
如果任何人已经想出这种
If anyone has already figured out this kind of plot with or without ggplot2 I would greatly appreciate his or her solution.
推荐答案
在 ggplot
In ggplot
you can really only use alpha
for what you're asking. I've made up some data:
df1 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))
df2 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))
df3 <- data.frame(X=rnorm(16), Y=rnorm(16), S=rep(1:4,times=4), Class=rep(LETTERS[1:4], each=4))
ggplot(df1, aes(x)) + geom_point(aes(y=Y, colour=S, shape=Class))
df1$id <- 1
df2$id <- 2
df3$id <- 3
df.list <- list(df1, df2, df3)
df.all <- ldply(df.list, rbind)
ggplot(df.all, aes(X, Y)) + geom_point(aes(colour=as.factor(id), shape=Class, alpha=S))
不确定是否符合您的要求...
Not sure if that meets your requirements...
这篇关于如何在一个图中有多个颜色刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!