Can someone please help me find what is wrong with this code below:
df <- read.csv("F:/Complete_Projects/acceptability_example.csv", stringsAsFactors = F)
#> Warning in file(file, "rt"): cannot open file 'F:/Complete_Projects/
#> book_chapter_CRC/acceptability_example.csv': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
colnames(df)[1] = "timedata"
#> Error in `colnames<-`(`*tmp*`, value = "timedata"): attempt to set 'colnames' on an object with less than two dimensions
colnames(df)[2] = "score"
#> Error in `colnames<-`(`*tmp*`, value = c(NA, "score")): attempt to set 'colnames' on an object with less than two dimensions
p <- ggplot(df, aes(x = timedata, y = score)) +
theme_bw() +
xlab("Oxidized flavor on 15-point scale") +
ylab("Overall liking on 9-point hedonic scale") +
geom_point(color = "#04fbfb", size = 2) +
geom_smooth(method=lm, linetype = "dashed", color="black") +
coord_cartesian(ylim=c(1, 9)) +
scale_y_continuous(breaks=seq(1, 9, 1)) +
stat_poly_eq(formula = y ~ x,
aes(label = paste(..eq.label..)),
parse = TRUE, label.y = 0.90, label.x = 0.7) +
stat_poly_eq(formula = y ~ x,
aes(label = paste(..rr.label..)),
parse = TRUE, label.y = 0.85, label.x = 0.7) +
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face="bold"),
axis.text.x= element_text(face = "bold"),
axis.text.y = element_text(face = "bold"),
panel.border = element_blank(),
axis.line = element_line())
#> Error in ggplot(df, aes(x = timedata, y = score)): could not find function "ggplot"
p + annotate("segment", x = 0, xend = 4, y = 5.8, yend = 5.8, colour = "blue", linetype=5) +
annotate("segment", x = 4, xend = 4, y = 0, yend = 5.8, colour = "blue", linetype=2) +
annotate("segment", x = 0, xend = 4.9, y = 5.8, yend = 5.8, colour = "blue", linetype=5) +
annotate("segment", x = 4.9, xend = 4.9, y = 0, yend = 5.8, colour = "red", linetype=2) +
annotate("segment", x = 0, xend = 4.9, y = 5.8, yend = 5.8, colour = "blue", linetype=5) +
annotate("segment", x = 3, xend = 3, y = 0, yend = 5.8, colour = "green", linetype=2) +
annotate("text", x = 1.5, y = 5.5, colour = "blue", label = "Cut-off point") +
annotate("text", x = 2.9, y = 1.5, colour = "blue", label = "Sensory\nfailure") +
annotate("text", x = 5, y = 5, colour = "red", label = "95% U-CI") +
annotate("text", x = 2.5, y = 4, colour = "green", label = "95% L-CI")
#> Error in eval(expr, envir, enclos): object 'p' not found
Created on 2022-01-28 by the reprex package (v2.0.1)