The change that @FJCC suggested is needed in any case, but I think you could also having trouble with reading the data. That is not done with
#turn the file into a data frame
df <- data.frame(data = filename) # NOT CORRECT !
I give an example of (first writing some test data to a file and then) reading from a file in a data.frame :
# write some test data
filename = 'gintonic.txt'
mydata = data.frame(
data.Specimen.date = 1:4,
data.Cumulative.lab.confirmed.cases.rate = c(0.4, 0.3, 0.35, 0.45),
data.Area.type = c("Region","Region","Nation","Nation")
)
write.csv(mydata,filename)
Your code could then look like
filename = 'gintonic.txt'
df = read.csv(filename)
# create a df of regions
regdata <- df[df$data.Area.type == "Region",]
nrow(regdata)
# import ggplot2 into r
library(ggplot2)
# and use the adapted code by FJCC:
p <- ggplot(data = regdata,
aes(x = data.Specimen.date,
y = data.Cumulative.lab.confirmed.cases.rate))
p + geom_line()