I am not sure why this error comes up or how to fix the problem.
#turn the file into a data frame
df <- data.frame(data = filename)
df
#check that all the rows are still in the data frame
nrow(df)
# import ggplot2 into r
library(ggplot2)
#check all the headings for the data frame
names(df)
str(df)
# create a df of regions
regdata <- df[df$data.Area.type == "Region",]
nrow(regdata)
str(regdata)
natdata <- df[df$data.Area.type == "Nation",]
nrow(natdata)
str(natdata)
utladata <- df[df$data.Area.type == "Upper tier local authority",]
nrow(utladata)
ltladata <- df[df$data.Area.type == "Lower tier local authority",]
nrow(ltladata)
str(df$data.Specimen.date)
#chart regional cases rate
Please could you advice me.
p <- ggplot(data = 'regdata', aes(x = 'data.Specimen.date', y = 'data.Cumulative.lab.confirmed.cases.rate'))
p + geom_line()
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()