此演示如何使用ggplot函数操作ggplot的多个图例,如顺序、标题颜色。我想知道是否可以单独修改每个图例的背景色。谢谢!
ggplot(mpg, aes(displ, cty)) +
# I tired to use legend.background and a list of colors in fill to individually change the color, but is it not working
theme(legend.background=element_rect(fill=c('brown','grey','wh
我有一些数据集,其中包含的图例条目比通过颜色或符号显示的图例条目要多得多。它实际上是一道彩虹,但跨越了如此多的图例条目,以至于它们使得情节比宽度高得多。
由于图例并不像舒适的绘图大小一样重要,所以在将绘图保存到PNG之前,我只是预览并删除它们。
如下所示:
library(ggplot2)
p <- ggplot(diamonds, aes(cut, depth)) + geom_point(aes(colour = factor(carat), size = price))
p
p <- p + theme(legend.position = "none")
p
我正在使用ggplot2中的循环创建一个绘图列表(不带图例)。然后,我单独创建了一个图例,并尝试使用grid.arrange和grobs函数打印组合的绘图。它会创建组合的绘图,但不包含图例。有人能帮我解决这个问题吗?
我在这里附上了我的代码:
df1<-data.frame(x=1:10,y1=rnorm(10),y2=rnorm(10),y3=rnorm(10),y4=rnorm(10),y5=rnorm(10))
df2 <- melt(df1,id.vars="x")
plot.list = list()
for (i in 1:3){
p <-
继续我的问题:
我可以用这些代码创建一个数字。
x <- 1:100
y <- x * x
z <- abs(cos(x * pi / (max(x))))
df <- data.frame(x = x, y = y, z = z)
library(ggplot2)
mult <- 200
ggplot(df, aes(x, y)) + geom_line() + geom_ribbon(aes(ymin=y-mult*z, ymax=y+mult*z))
但我现在的问题是如何创造一个传说来反映线条的大小。例如,此图中的图例
ggplot(df,
我试图用ggplot2分别用fill和alpha对两个离散变量进行可视化。这样做的标准方法如下:
#creating data and building the basic bar plot
library(ggplot2)
myleg<-read.csv(text="lett,num
a,1
a,2
b,1
b,2
h,1
h,2
h,3
h,4")
ggplot(myleg,aes(lett,alpha=factor(num),fill=lett)) +geom_bar(position=position_stack(reverse=T)) +scale_alpha_