0

I used the same code to plot my data last week, and got it all right. I updated the data with new rows, so this is the only thing I changed, but then ggplot does not plot the data but a bunch of numbers as shown in the pictures I attached.

I'm sure it is something about how the data is coded, but when it happened last week, what I did was to use as.numeric, and that's it.

**# Read the data

experiment_6 <- read.csv("Data_Experiments.xlsx - experiment_6.csv", header=TRUE)

#clean the irrelevant rows

experiment_6_clean <- experiment_6[-c(1,2), ]

#check if it data.frame
is.data.frame(experiment_6_clean)

#remove Nas from dataset
#experiment_6_clean %>% drop_na()

#select relevant data 

experiment_6_clean<- experiment_6_clean[1:517,]

#rename columns

experiment_6_clean<- dplyr::rename(experiment_6_clean,
   mean_S_both_Par= X, plusSD_S_both_Par= X.1, minusSD_S_both_Par=X.2, 
   mean_S_both_Agl=X.3,plusSD_S_both_Agl= X.4, minusSD_S_both_Agl= X.5,
   mean_M_both_Par= X.6,plusSD_M_both_Par= X.7, minusSD_M_both_Par= X.8, 
   mean_M_both_Agl= X.9, plusSD_M_both_Agl= X.10,minusSD_M_both_Agl= X.11, 
   mean_L_water_Sch= X.12, plusSD_L_water_Sch= X.13, minusSD_L_water_Sch= X.14, 
   mean_L_both_Sch= X.15, plusSD_L_both_Sch=X.16, minusSD_L_both_Sch= X.17,
   Time= X1)

#make all relevant data  numeric
Time<- as.numeric(experiment_6_clean$Time)

#small_pots_both_par------4"_2mm_BothSides_Par


mean_S_both_Par<- as.numeric(experiment_6_clean$mean_S_both_Par) 
plusSD_S_both_Par<- as.numeric(experiment_6_clean$plusSD_S_both_Par)  
minusSD_S_both_Par<- as.numeric(experiment_6_clean$minusSD_S_both_Par)

#small_pots_both_agl---4"_2mm_BothSides_Agl 

mean_S_both_Agl<- as.numeric(experiment_6_clean$mean_S_both_Agl) 
plusSD_S_both_Agl<- as.numeric(experiment_6_clean$plusSD_S_both_Agl)  
minusSD_S_both_Agl<- as.numeric(experiment_6_clean$minusSD_S_both_Agl)


#medium_pots_both_par---6"_2mm_BothSides_Par

mean_M_both_Par<- as.numeric(experiment_6_clean$mean_M_both_Par) 
plusSD_M_both_Par<- as.numeric(experiment_6_clean$plusSD_M_both_Par)  
minusSD_M_both_Par<- as.numeric(experiment_6_clean$minusSD_M_both_Par)



#medium_pots_both_agl---6"_2mm_BothSides_Agl

mean_M_both_Agl<- as.numeric(experiment_6_clean$mean_M_both_Agl) 
plusSD_M_both_Agl<- as.numeric(experiment_6_clean$plusSD_M_both_Agl)  
minusSD_M_both_Agl<- as.numeric(experiment_6_clean$minusSD_M_both_Agl)


#large_pots_water_Sch---10"_4mm_WaterSide_Sch

mean_L_water_Sch<- as.numeric(experiment_6_clean$mean_L_water_Sch) 
plusSD_L_water_Sch<- as.numeric(experiment_6_clean$plusSD_L_water_Sch)  
minusSD_L_water_Sch<- as.numeric(experiment_6_clean$minusSD_L_water_Sch)

#large_pots_both_Sch---10"_5mm_BothSides_Sch

mean_L_both_Sch<- as.numeric(experiment_6_clean$mean_L_both_Sch) 
plusSD_L_both_Sch<- as.numeric(experiment_6_clean$plusSD_L_both_Sch)  
minusSD_L_both_Sch<- as.numeric(experiment_6_clean$minusSD_L_both_Sch)


experiment_6_clean<- as.data.frame(experiment_6_clean)

#plot

#create key 
colors <- c(mean_S_both_Par = "light blue", mean_S_both_Agl = "red", mean_M_both_Par = "orange",
            mean_M_both_Agl = "violet", mean_L_water_Sch = "pink", mean_L_both_Sch = "yellow")

#compare all six pots 
all_six<- ggplot(experiment_6_clean, aes(x=Time))+ 
  geom_smooth(aes(y=mean_S_both_Par, colour = "mean_S_both_Par"), size = 2, se=TRUE ) +
  geom_smooth(aes(y=mean_S_both_Agl, colour = "mean_S_both_Agl"), size = 2, se=TRUE)+
  geom_smooth(aes(y=mean_M_both_Par, colour = "mean_M_both_Par"), size = 2, se=TRUE)+
  geom_smooth(aes(y=mean_M_both_Agl, colour = "mean_M_both_Agl"),size = 2, se=TRUE )+
  geom_smooth(aes(y=mean_L_water_Sch, colour = "mean_L_water_Sch"),size = 2, se=TRUE)+
  geom_smooth(aes(y=mean_L_both_Sch,colour = "mean_L_both_Sch"),size = 2, se=TRUE)+
  labs(title="Experiment 6", subtitle="All Plants", caption="20 days",
  y="Mositure Level", x="Time",  color = "Group") +
  scale_color_manual(values = colors)+
  theme(plot.title=element_text(size=20, face="bold"),                                                        axis.text.x=element_text(size=15), 
      axis.text.y=element_text(size=15))+ 
  coord_cartesian(ylim=c(-100, 150), xlim=c(0, 25))+
     theme_bw()
all_six**

what I got this weekwhat I had last week

  • 3
    Are you sure you y-axis data is numeric? It looks like it is encoded as a character or factor. Might be because one new data entry point might have a comma instead of a period or something. – teunbrand May 06 '21 at 10:52
  • Could you put the data in your questions? For example by using `dput(head(experiment_6_clean , 10))`. That would make it a lot easier to answer your question, rather than guessing. – Annet May 06 '21 at 11:24
  • structure(list(X = c("8.666666667", "8.833333333", "10.5", "10", "10.66666667", "9.833333333", "9.333333333", "10.16666667", "9.833333333", "9"), X.1 = c("117.3785182", "117.992697", "119.5719946", "119.9799982", "120.0826923", "117.7989143", "117.5657992", "118.7270953", "118.2591913", – Hodaya Levy May 06 '21 at 11:32
  • structure(list(X = c("8.666666667", "8.833333333"), X.1 = c("117.3785182", "117.992697"), X.2 = c("-100.0451849", "-100.3260303"), X.3 = c("109.3333333", "109.1666667"), X.4 = c("217.9144858", "217.0562707"), X.5 = c("0.7521808866", "1.277062595"), X.6 = c("-0.3333333333", "1.166666667"), X.7 = c("40.54534897", "41.62116786"), X.8 = c("-41.21201563", "-39.28783453"), X.9 = c("-69.33333333", "-68.5"), X.10 = c("-42.10344779", "-41.49814821"), X.11 = c("-96.56321888", "-95.50185179"), – Hodaya Levy May 06 '21 at 11:33
  • So at the meantime I figured out that the rename caused it. When I do not run it but do as.numeric directly it suddenly works.... – Hodaya Levy May 06 '21 at 11:36

0 Answers0