Reputation: 301
I want to read some data in R from a csv file and then visualize in form of a boxplot.
I am getting always an error that the some data is not numeric : Error in mkRespMod(fr, REML = REMLpass) : response must be numeric
.
This is my code in R:
library(tidyverse)
library(lme4)
library(emmeans)
library(multcomp)
# 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\\alex\\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)
This is my data frame:
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
And this how I create my csv file:
Upvotes: 0
Views: 235
Reputation: 389335
You have semi-colon separated data so use read.csv2
or read.csv
with semi-colon as separator. Assuming the first dot is not needed we can remove those and convert the data to numeric.
data <- read.csv2('data.csv')
data$NEE <- as.numeric(sub('.', '', data$NEE, fixed = TRUE))
lm_NEE <- lmer(NEE ~ cc_variant + (1|Date), data=data)
This fixes the first step but it fails at the next step with cld
, not sure about the issue there.
Upvotes: 1