我试图使某些绘图透明,但是当我添加“ alpha”时,出现以下错误。有人知道我应该如何纠正吗?
Error: `data` must be a data frame, or other object coercible by `fortify()`, not a character vector
这是我的代码:
graphics.off()
rm(list=ls())
library(ggplot2)
library(dplyr)
library(tidyr)
library(tidyverse)
setwd("F:/Data/")
file1<-read.csv("F:/Data/diam.csv")
cl<-rainbow(20)
names(file1)
ggplot(data=file1, aes(x = No.)) +
geom_line(aes(y = X1), colour="red")+
geom_line(aes(y = X2), colour="coral4",alpha(.4))+
geom_line(aes(y = X3), colour=cl[8],alpha(.4))+
geom_line(aes(y = X4), colour="magenta")+
xlab("Image ")+ylab("n pores<0.13")+
theme(legend.position="bottom")
您的csv文件中可能有些奇怪的内容,使得输出read.csv是与数据帧不同的数据类型。我会用str(file1)和/或head(file1)来确保对象看起来像您想要的那样。如果是这样,您可以尝试通过执行file1
也许是alpha = 0.4
library(ggplot2)
ggplot(data=file1, aes(x = No.)) +
geom_line(aes(y = X1), colour="red")+
geom_line(aes(y = X2), colour="coral4",alpha = 0.4)+
geom_line(aes(y = X3), colour=cl[8],alpha = 0.4)+
geom_line(aes(y = X4), colour="magenta")+
xlab("Image ")+ylab("n pores<0.13")+
theme(legend.position="bottom")