I am trying to read some data written in R from a csv file instead using the data frame.
I used read.csv
to extract the data from the file but I got always this error In read.table(file = file, header = header, sep = sep, quote = quote, : line 1 appears to contain embedded nulls
.
This is a piece of the code in R using the data frame:
COL <- c("Fallow" = "slategray", "Mustard" = "red3" , "Mix4" = "orchid3", "Mix12"= "orange4")
SHP <- c("Fallow"=21,"Mustard"=22,"Mix4"=23, "Mix12"=24)
# generate data frame with original data
data <- data.frame(cc_variant = structure(c(1L, 1L, 1L, 3L, 4L, 2L, 3L, 4L, 2L, 2L, 4L, 3L), .Label = c("Fallow", "Mustard", "Mix4", "Mix12"), class = "factor"),
Date = structure(c(17092, 17093, 17098, 17092, 17092, 17092, 17093, 17093, 17093, 17098, 17098, 17098), class = "Date"),
NEE = c(52.3186092, 36.752742, 34.590816, -516.868370737168, -617.110003978854, -182.24567563611, -102.63776100067, -431.558870280712, -139.041211720174, -114.099387563412, -400.212603947375, -175.332083704246)
)
lm_NEE <- lmer(NEE ~ cc_variant + (1|Date), data=data)
df_NEE <- cld(emmeans(lm_NEE, specs ="cc_variant"), Letters=letters, sort=FALSE)
# Plot for BFS
ggplot(data, aes(x= cc_variant, y=NEE, fill= cc_variant))+
geom_boxplot()+
scale_fill_manual(values = COL, guide=FALSE)+
geom_text(data= df_NEE ,aes(y=-600,x=cc_variant, label=.group))+
labs(x="Catch crop variant", y=expression("NEE (mg CO"[2]~"- C"~m^{-2}~h^{-1}~")"), fill="")+
theme_myBW
ggsave("Fig1.png", width = 84, height = 70, units = "mm", dpi = 600)
This how the data frame looks:
cc_variant Date NEE
1 Fallow 2016-10-18 52.31861
2 Fallow 2016-10-19 36.75274
3 Fallow 2016-10-24 34.59082
4 Mix4 2016-10-18 -516.86837
5 Mix12 2016-10-18 -617.11000
6 Mustard 2016-10-18 -182.24568
7 Mix4 2016-10-19 -102.63776
8 Mix12 2016-10-19 -431.55887
9 Mustard 2016-10-19 -139.04121
10 Mustard 2016-10-24 -114.09939
11 Mix12 2016-10-24 -400.21260
12 Mix4 2016-10-24 -175.33208
This is my try:
# set vector with colors and label
COL <- c("Fallow" = "slategray", "Mustard" = "red3" , "Mix4" = "orchid3", "Mix12"= "orange4")
SHP <- c("Fallow"=21,"Mustard"=22,"Mix4"=23, "Mix12"=24)
# generate data frame with original data
data <- read.csv("C:\\Users\\aganfoud\\Desktop\\orkg-stencila\\Gentsch2020\\data.csv", header=T, sep = ';')
datalm_NEE <- lmer(NEE ~ cc_variant + (1|Date), data=data)
df_NEE <- cld(emmeans(lm_NEE, specs ="cc_variant"), Letters=letters, sort=FALSE)
# Plot for BFS
fig1 <- ggplot(data, aes(x= cc_variant, y=NEE, fill= cc_variant))+
geom_boxplot()+
scale_fill_manual(values = COL, guide=FALSE)+
geom_text(data= df_NEE ,aes(y=-600,x=cc_variant, label=.group))+
labs(x="Catch crop variant", y=expression("NEE (mg CO"[2]~"- C"~m^{-2}~h^{-1}~")"), fill="")+
theme_myBW
ggsave("Fig1.png", width = 84, height = 70, units = "mm", dpi = 600)
and finally this is how I create my csv file: