rggplot2alpha-transparency

Trying to solve the error: Error: `data` must be a data frame, or other object coercible by `fortify()`, not a character vector


I have tried to make some of my plots transparent but when I added the "alpha" I have got the following error. Does anybody have any idea how I should correct it?

Error: `data` must be a data frame, or other object coercible by `fortify()`, not a character vector

Here is my code:

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")

Solution

  • Perhaps, it would be 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")