[英]Setting the color label and varying the color palette in qplot
Using the code below, i can set the labels for x and y axis, but can't set the label for color that is cyl
here. 使用下面的代码,我可以为x和y轴设置标签,但在这里不能为
cyl
设置颜色。 The documentation provides no way around. 该文档无法解决。
qplot(mpg, wt, data=mtcars, colour=cyl,xlab="MPG",ylab="WT")
How can I vary the color palette herein qplot
? 如何在
qplot
更改调色板? So, I wish to do something like in the code below: 因此,我希望在下面的代码中执行以下操作:
x <- runif(100) y<-runif(100) time<-runif(100) pal <- colorRampPalette(c('white','black')) cols <- pal(10)[as.numeric(cut(time,breaks = 10))] plot(x,y,pch=19,col = cols)
You can use scale_colour_continuous
for both tasks. 您可以对两个任务都使用
scale_colour_continuous
。
library(ggplot2)
qplot(mpg, wt, data = mtcars, colour = cyl, xlab = "MPG", ylab = "WT") +
scale_colour_continuous(name = "Cylinders", low = "white", high = "black")
Here, the name
parameter is the label for the colour scale. 在这里,
name
参数是色标的标签。 The parameters low
and high
denote the lower and upper limits of the continuous colour scale. 参数
low
和high
表示连续色标的下限和上限。
If you want to specify a continuous colour scale with three colours, you can use scale_colour_gradient2
: 如果要指定具有三种颜色的连续色标,可以使用
scale_colour_gradient2
:
qplot(mpg, wt, data = mtcars, colour = cyl, xlab = "MPG", ylab = "WT") +
scale_colour_gradient2(name = "Cylinders", midpoint = median(mtcars$cyl),
low = "red", mid = "green", high = "black")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.