0

Using the following data frame:

sdf<-data.frame(hours=gl(n=3,k=1,length=9,labels=c(0,2,4)),    
                count=c(4500,1500,2600,4000,800,200,1500,50,20),
                machine=gl(n=3,k=3,length=9,labels=c("A","B","C")))

The following graph can be produced using either of these scripts:

ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine))+
  geom_area(data=sdf[sdf$machine=="A",])+
  geom_area(data=sdf[sdf$machine=="B",])+
  geom_area(data=sdf[sdf$machine=="C",])

ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine))+
  geom_area(position="dodge")

enter image description here

The color can easily be changed, but changing the alpha value also changes the legend:

ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine,alpha=machine))+
  geom_area(position="dodge")+
  scale_fill_manual(values=c("chocolate1","goldenrod","pink"))+
  scale_alpha_manual(values=c(0.01, 0.2, .1),guide=F)

enter image description here

Ideally, the legend will not fade to the same alpha values. This might sound strange for an individual graph, but the result will be part of a .gif file.

Question: What script can alter the alpha values for individual graphs yet keep the solidity of colors in the legend?

4

1 回答 1

3

在这里回答而不是评论,以便我可以发布图像

这很奇怪:使用 R 3.0.0 和ggplot20.9.3.1,以下代码(与您发布的相同)

ggplot(data=sdf,aes(x=hours,y=count,group=machine,fill=machine,alpha=machine))+
  geom_area(position="dodge")+
  scale_fill_manual(values=c("chocolate1","goldenrod","pink"))+
  scale_alpha_manual(values=c(0.01, 0.2, .1),guide=F)

给我

在此处输入图像描述

指南中alpha的第 1 位。这是有道理的,因为guide=F已经关闭了scale_alpha_manual指南,允许alpha默认为 1。

于 2013-08-30T00:38:53.757 回答