Plot() function is not working

98 views
Skip to first unread message

Lauren Keller

unread,
Sep 22, 2022, 5:43:53 PM9/22/22
to ggplot2
hello, 

I've been trying to trouble shoot why my plot(p1) is not working. I tried eliminating the N/A values that I had by just removing the row entirely and also by turning them all to zero with an iteration but I keep getting the same error messages (see below) any help on this would be much appreciated! Thank you!
error message :

error in plot.window(...):need finite 'ylim' values
in addition: warning messages:
1: in xy.coords(x,y,xlabel,ylabel,log):NAs introduced by coercion
2: in min(x):no non-missing arguments to min; returning Inf
3: in max(x): no non-missing arguments to max; returning -Inf

my code:
library(dplyr)
library(stringr)
setwd('C://Users/Abstract_Data')
datadir<-'C://Users/Abstract_Data'
outputdir<-'C://Users/Abstract_Data/Output'
demo<- read.csv('RAM_V2_PHQTOT_ASRMTOT.csv')

moods<-read.csv('RAM_MOOD20_Data_Pulled_09_14_2022.csv')

df<- merge(demo, moods, by = 'CRC_ID' )
#df<-df[complete.cases(df),]

df$Global_Vigor <- (df$Q1 + 300 - df$Q8 - df$Q4 - df$Q6) / 4
df$Global_Affect<- (df$Q5) + (df$Q7) + 200 - (df$Q2) - (df$Q3) / 4

Timedf<-data.frame(STDYDESC=c("WAKEUP","AM TEST","MRI","PM TEST"),
                             Time=c(1,2,3,4))
df<-df%>%inner_join(Timedf, by="STDYDESC")

df<-df%>% mutate(across('MOODSMAN_SCALE',str_replace, 'MODERATE|HIGH','MODERATE/HIGH'))

df$GROUP <- as.factor(df$MOODSMAN_SCALE)

for(y in 7:ncol(df)){if (is.na(df[7,y])) df[7,y] = 0}

library(ggplot2)
library(ggpubr)
library(reshape2)
p1 <- ggplot(df, aes(x=Time, y=Global_Vigor, colour = GROUP))
p1 +
  stat_summary(fun = mean, geom="point") +
  stat_summary(fun = mean, geom = "line", aes(group = GROUP)) +
  stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2) +
  labs(x = "Time", y = "Global_Vigor", colour = "GROUP")
plot('p1')



Reply all
Reply to author
Forward
0 new messages