ggplot2 code runs and updates plot but no I see a bunch of numbers instead of data

71 views Asked by At

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

0

There are 0 answers