我想知道如何更改图例框中的按键标签。我需要被世界“Inactivo”我试图用scale_fill_discrete
由单词“ACTIVO”和值2代替值1,但它不工作我如何手动更改ggplot2图例中的键标签值?
这是该数据帧的样本
structure(list(ZPIE = c(4109L, 4463L, 4624L, 4267L, 4569L, 4656L,
3976L, 4136L, 4139L, 4694L, 4354L, 4615L, 4183L, 4113L, 4508L,
4035L, 4443L, 4709L, 4575L, 4363L), ecd = c(0.0873015873015873,
0.779220779220779, 0.916666666666667, 0.396825396825397, 0.876984126984127,
0.961038961038961, 0.0649350649350649, 0.134920634920635, 0.285714285714286,
0.948412698412698, 0.55952380952381, 0.904761904761905, 0.337662337662338,
0.233766233766234, 0.785714285714286, 0.0198412698412698, 0.698412698412698,
0.956349206349206, 0.884920634920635, 0.579365079365079), ACTIVIDAD = structure(c(1L,
2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("1", "2"), class = "factor")), .Names = c("ZPIE",
"ecd", "ACTIVIDAD"), row.names = c(166L, 258L, 202L, 158L, 207L,
319L, 288L, 98L, 329L, 46L, 15L, 1L, 277L, 272L, 92L, 33L, 23L,
201L, 194L, 197L), class = "data.frame")
这是我写的,以获得剧情代码:
a <- ggplot(intactos,aes(x = ZPIE, y = ecd))+
geom_line(aes(group = ACTIVIDAD,colour = ACTIVIDAD,linetype=ACTIVIDAD),size = 1,colour="black")+
xlab("Altitud m") +
ylab("Distribucion Acumulada (%)")+
scale_x_continuous(limits=c(3500,5000),breaks=c(3500,3750,4000,4250,4500,4750,5000))+
geom_vline(aes(xintercept=4000),linetype="dashed",size = 1)+
geom_text(aes(4050,.85,label = "0°C MAAT isoterma")
,vjust=0,
,fontface= 'plain'
,colour='black'
,size=5)+
theme( plot.background = element_rect(fill="white")
,panel.background = element_rect(fill='white')
,panel.grid.major = element_line(colour = 'grey', linetype = 'dashed')
,panel.grid.minor = element_line(colour = 'white', linetype = 'dashed')
,panel.border = element_blank()
,axis.line = element_line(colour = 'black')
,axis.text.x=element_text(colour="black")
,axis.text.y=element_text(colour="black")
,panel.grid.major =element_line(colour = 'grey', linetype = 'dashed')
,legend.key=element_rect(fill="white",colour="white"),legend.position=c(0.25,0.7))
a + coord_flip()
这里是我试图创建 https://dl.dropbox.com/u/11320858/plot_zoom_png2
欢迎来到Stack Overflow。当我不久前加入时,我对这里的工作方式感到有点困惑。这个想法是当你提出一个问题时提供一个可复制的代码示例。你提供了一些代码,这很好,但是我们看不到你的数据结构。所以请使用'dput(head(intactos,20))'并将结果粘贴到您的问题中。如果数据是专有的,则制作模仿真实数据结构的“假”数据。阅读[这篇有用的文章](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)寻求帮助。 – SlowLearner
谢谢。我刚刚添加了一个示例数据框 – gmoazocar
谢谢你。但是,链接到的图形显示两个数据系列,而数据框似乎只有一个。我在猜测你遗漏了数据框中的分组变量。那是ACTIVIDAD在你的代码中引用了什么?如果您可以提供(或生成)两个系列的数据,我们应该可以提供帮助。 – SlowLearner