R Ggplot2没有';不要全部打印
我不明白为什么我的代码不起作用:R Ggplot2没有';不要全部打印,r,R,我不明白为什么我的代码不起作用: if(formula=="ValueA"){ df<-melt(f,id =c("ValueA")) colnames(df)[colnames(df) == 'variable'] <- 'Time' if(yaxis=="YA"){ colnames(df)[colnames(df) == 'value'] <- 'YA' pl<- ggplot(df, a
if(formula=="ValueA"){
df<-melt(f,id =c("ValueA"))
colnames(df)[colnames(df) == 'variable'] <- 'Time'
if(yaxis=="YA"){
colnames(df)[colnames(df) == 'value'] <- 'YA'
pl<- ggplot(df, aes(Time, YA, fill=ValueA))}
if(yaxis=="YB"){
colnames(df)[colnames(df) == 'value'] <- 'YB'
pl<- ggplot(df, aes(Time, YB, fill=ValueA))}
if(yaxis=="YC"){
colnames(df)[colnames(df) == 'value'] <- 'YC'
pl<- ggplot(df, aes(Time, YC, fill=ValueA))}
if(yaxis=="YD"){
colnames(df)[colnames(df) == 'value'] <- 'YD'
pl<- ggplot(df, aes(Time, YD, fill=ValueA))}
if(type=="line"){
pl + geom_line(aes(color=ValueA,group=ValueA)) +theme(
axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle(paste(title))+ YD theme( panel.border = element_rect(colour = "black", fill=NA, size=1),legend.direction ="vertical",legend.position = "right")+guides(color=guide_legend(ncol=1))+scale_y_continuous(labels=comma)
}
if(type=="bar"){
pl + geom_bar(stat="identity") +theme(
axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle(paste(title))+ YD theme( panel.border = element_rect(colour = "black", fill=NA, size=1),legend.direction ="vertical",legend.position = "right")+guides(fill=guide_legend(ncol=1))+scale_y_continuous(labels=comma)
}
}
if(formula=="ValueB"){
df<-melt(f,id =c("ValueB"))
colnames(df)[colnames(df) == 'variable'] <- 'Time'
if(yaxis=="YA"){
colnames(df)[colnames(df) == 'value'] <- 'YA'
pl<- ggplot(df, aes(Time, YA, fill=ValueB))}
if(yaxis=="YB"){
colnames(df)[colnames(df) == 'value'] <- 'YB'
pl<- ggplot(df, aes(Time, YB, fill=ValueB))}
if(yaxis=="YC"){
colnames(df)[colnames(df) == 'value'] <- 'YC'
pl<- ggplot(df, aes(Time, YC, fill=ValueB))}
if(yaxis=="YD"){
colnames(df)[colnames(df) == 'value'] <- 'YD'
pl<- ggplot(df, aes(Time, YD, fill=ValueB))}
if(type=="line"){
pl+ geom_line(aes(color=ValueB,group=ValueB))+theme(
axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle(paste(title))+ YD theme( panel.border = element_rect(colour = "black", fill=NA, size=1),legend.direction ="vertical",legend.position = "right")+guides(color=guide_legend(ncol=1)) +scale_y_continuous(labels=comma)
}
if(type=="bar"){
pl + geom_bar(stat="identity")+theme(
axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle(paste(title))+ YD theme( panel.border = element_rect(colour = "black", fill=NA, size=1),legend.direction ="vertical",legend.position = "right")+guides(fill=guide_legend(ncol=1)) +scale_y_continuous(labels=comma)
}
}
print(pl)
}
Plotsf<-Plots(Df,"Title","line","YA")
输出是完美的。有人可以解释为什么pl+
不起作用?
谢谢所以答案是将变量带入,而不仅仅是写:
pl + ... added stuff
这是毫无意义的。。。改用:
pl <- pl + ... added stuff
pl也许可以试试pl@Dilettant它奏效了……谢谢,对不起,但我对这些东西很在行。我从中得出了答案。如果您愿意,可以接受;-)
pl <- pl + ... added stuff