缩放填充离散不改变图例标签-GGR绘图

缩放填充离散不改变图例标签-GGR绘图,r,ggplot2,legend,legend-properties,R,Ggplot2,Legend,Legend Properties,当我在R中使用ggplot2时,我在更改图例标签时遇到问题。我绘制了一个线条图,其中有7条线条对应于在温度区(x)上采用进给策略(y)的试样比例。到目前为止,我已经尝试使用两种不同的方法来更改标签(目前为1-7),但都没有更改任何内容。以下是我尝试过的: plot + scale_fill_discrete("Feeding Type",breaks=c("1", "2", "3", "4", "5", "6", "7"), labels=c("Fungivorous", "Herbivo

当我在R中使用ggplot2时,我在更改图例标签时遇到问题。我绘制了一个线条图,其中有7条线条对应于在温度区(x)上采用进给策略(y)的试样比例。到目前为止,我已经尝试使用两种不同的方法来更改标签(目前为1-7),但都没有更改任何内容。以下是我尝试过的:

plot + scale_fill_discrete("Feeding Type",breaks=c("1", "2", "3", "4", "5", "6", "7"),
   labels=c("Fungivorous", "Herbivorous", "Saprophagous", "Predacious", "Xylophagous", "Parasitoid", "Algivorous"))


使用示例数据集更新代码,该示例数据集根据进给(颜色和线型)生成具有7条不同线条的绘图,显示比例对温度的响应:

feedings <- c("Fungivorous", "Herbivorous", "Saprophagous", "Predacious",
        "Xylophagous", "Parasitoid", "Algivorous")

tempzone <- c("-5 to 0", "0 to 5","5 to 10", "10 to 15")
tempzone <- factor(tempzone, levels=c("-5 to 0", "0 to 5","5 to 10", "10 to 15"))

proportion <- c(0.05,0.1,0.15,0.3)

F <- data.frame(Temperature=tempzone, Proportion=proportion, Feeding="Fungivorous")
H <- data.frame(Temperature=tempzone, Proportion=proportion+.1, Feeding="Herbivorous")
S <- data.frame(Temperature=tempzone, Proportion=proportion+.2, Feeding="Saprophagous")
P <- data.frame(Temperature=tempzone, Proportion=proportion+.3, Feeding="Predacious")
X <- data.frame(Temperature=tempzone, Proportion=proportion+.4, Feeding="Xylophagous")
Pa <- data.frame(Temperature=tempzone, Proportion=proportion+.5, Feeding="Parasitoid")
A <- data.frame(Temperature=tempzone, Proportion=proportion+.6, Feeding="Algivorous")

data <- rbind.data.frame(F,H,S,P,X,Pa,A)

feedingPLOT <- ggplot(data=data, aes(x=Temperature, y=Proportion, group=Feeding, linetype=Feeding, color=Feeding))+
        geom_line() + 
        scale_color_manual(values=c("Fungivorous"="blue","Herbivorous"="red","Saprophagous"="green",
                        "Predacious"="orange","Xylophagous"="black","Parasitoid"="purple","Algivorous"="yellow"))

feedings在ggplot()调用中没有使用fill参数,因此不能使用scale\u fill\u discrete()。您可能正在查找scale\u color\u discrete()、scale\u group\u discrete()或scale\u linetype\u discrete(),具体取决于要更改标签的图例。

我不会在ggplot调用中尝试更正标签。首先考虑变量,然后应用标签/级别和顺序。嗨,Tiffany,下面是生成绘图的代码:feedingPLOT我不确定数据的确切含义是第1行到第7行(只有7行…?)。无论如何,我制作了一个示例数据集,我认为它与您拥有的数据集类似,上面更新的代码应该更有用。
feedings <- c("Fungivorous", "Herbivorous", "Saprophagous", "Predacious",
        "Xylophagous", "Parasitoid", "Algivorous")

tempzone <- c("-5 to 0", "0 to 5","5 to 10", "10 to 15")
tempzone <- factor(tempzone, levels=c("-5 to 0", "0 to 5","5 to 10", "10 to 15"))

proportion <- c(0.05,0.1,0.15,0.3)

F <- data.frame(Temperature=tempzone, Proportion=proportion, Feeding="Fungivorous")
H <- data.frame(Temperature=tempzone, Proportion=proportion+.1, Feeding="Herbivorous")
S <- data.frame(Temperature=tempzone, Proportion=proportion+.2, Feeding="Saprophagous")
P <- data.frame(Temperature=tempzone, Proportion=proportion+.3, Feeding="Predacious")
X <- data.frame(Temperature=tempzone, Proportion=proportion+.4, Feeding="Xylophagous")
Pa <- data.frame(Temperature=tempzone, Proportion=proportion+.5, Feeding="Parasitoid")
A <- data.frame(Temperature=tempzone, Proportion=proportion+.6, Feeding="Algivorous")

data <- rbind.data.frame(F,H,S,P,X,Pa,A)

feedingPLOT <- ggplot(data=data, aes(x=Temperature, y=Proportion, group=Feeding, linetype=Feeding, color=Feeding))+
        geom_line() + 
        scale_color_manual(values=c("Fungivorous"="blue","Herbivorous"="red","Saprophagous"="green",
                        "Predacious"="orange","Xylophagous"="black","Parasitoid"="purple","Algivorous"="yellow"))