R ggplot2:动态图例标题
在我的代码中,图例的标题是自动生成的(X1,X2,…)。我如何使它如此,而不是X,它说“N=#”,其中N是在我的sappy函数中给出的R ggplot2:动态图例标题,r,ggplot2,legend,R,Ggplot2,Legend,在我的代码中,图例的标题是自动生成的(X1,X2,…)。我如何使它如此,而不是X,它说“N=#”,其中N是在我的sappy函数中给出的 library(ggplot2) library(reshape2) PlotBinom <- function(p) { x <- c(0:500) df <- sapply(seq(50,500,by=50), function(n) dbinom(x,n,p)) df <- data.frame(x,df) mel
library(ggplot2)
library(reshape2)
PlotBinom <- function(p) {
x <- c(0:500)
df <- sapply(seq(50,500,by=50), function(n) dbinom(x,n,p))
df <- data.frame(x,df)
melted.df <- melt(df,id.vars='x')
plot <- ggplot(melted.df,aes(x=x,y=value,colour=variable)) + geom_line()
print(plot)
}
PlotBinom(0.6)
PlotBinom(0.2)
库(ggplot2)
图书馆(E2)
PlotBinom添加一个调用,使用所需标签向量对缩放\u颜色\u离散
PlotBinom <- function(p) {
x <- c(0:500)
df <- sapply(seq(50,500,by=50), function(n) dbinom(x,n,p))
df <- data.frame(x,df)
melted.df <- melt(df,id.vars='x')
plot <- ggplot(melted.df,aes(x=x,y=value,colour=variable)) + geom_line()+
scale_colour_discrete( labels= paste( "N =" ,1:length( unique(melted.df$variable) ) ) )
print(plot)
}
PlotBinom