Use of the summarySE function to construct a graph in ggplot2

2

Hello, I'm looking for help to improve a script in R. I've developed it with the help of the ggplot2 package. I have some mistakes and I would like opinions. In the study, I evaluated the effect of intra and interspecific interaction between two species of tadpoles with two size classes "p" and "g" in the spatial resource use through two response variables: vertical displacement (sec) and horizontal displacement (cm) .

Errors:

    In the execution of the summary function: "/ Warning message: In qt (conf.interval / 2 + 0.5, datac $ N - 1): NaNs produced"

  • In the execution of legend.title = element_blank (): Error: unexpected symbol in: "legend.title = element_blank () legend.title"

follow the script

#Importar dados. Pacotes para o gráfico
pmed<-read.table("https://drive.google.com/open?id=1cET5cROSb-_D-cZYud3yKBHGR-qamind",header=T, sep=',') 
require(Rmisc)
require(ggplot2)
require(EnvStats)
require(sciplot)
require(dplyr)
summarypmed <- summarySE(pmed, measurevar="PV", groupvars=c("ID","INT"),na.rm=T)
# gráfico 1
                graf1 <- ggplot(summarypmed, aes(x=INT, y= PV, fill=INT)+ facet_wrap(~INT) +  
                geom_dotplot(binwidth=0.05,binaxis="y",stackdir = "center") +                  
                geom_errorbar(aes (ymin=PV.y-se,ymax=PV.y+se),width = 0.25,size=0.25)+         
                  xlab("Tratamentos") +                  
                  ylab(" Posição Vertical (cm)") +                  
                  geom_text(aes(label = paste("N", "==",N,sep = "")), 
                                              parse = TRUE, y=-0.15) +
                  geom_point(aes(y=PV.y), size=1,show.legend = F) +
                  theme_bw () +                  
                  scale_fill_manual(values=c("grey85","grey30")) +     
                    theme(axis.ticks.x=element_blank(),                          
                    axis.title.x=element_blank(),                    
                    axis.text=element_text(size=7),                    
                    axis.text.y=element_text(size=10),                    
                    axis.text.x=element_blank(),                    
                    axis.title.y=element_text(size=11),                    
                    plot.title=element_text(size=12, hjust = 0.5),                    
                    panel.grid=element_blank(),                    
                    plot.title=element_text(vjust=2),     
                    legend.title=element_blank())
    
asked by anonymous 09.07.2018 / 07:18

1 answer

3

This problem has no workaround with the data set provided. The help of the summarySE function reads as follows (my italics):

  

Gives count, mean, standard deviation , standard error of the mean , and confidence interval . >

The three measures I highlighted above are measures of dispersion or variability. All three are measures that depend on sample variance. The formula of the sample variance is given by

Notethatthesumisdividedbyn-1.Therefore,inordertobeabletomeasurethevariabilityinadataset,weneedatleasttwoobservations.Afterall,ifn=1,wewillhaveadivisionbyzero.

Inyouroriginalquestion,whengroupingthedatabyID(%with%),youaresayingthatyouwanttocalculatethevariabilitybyIDofthesubjects.Butlookatthefollowingcode,whereIcountthenumberofsubjectsperID:

library(dplyr)pmed%>%select(ID)%>%count()IDfreq122232425261718291102112122132152161171181191201211221231241251261271291301

ManyIDshaveonlyonesubject.Therefore,itisimpossibletocalculateameasureofvariabilityinthesecasesbecausedataismissing.Soyougotawarningaboutthegroupvars=c("ID","INT" (acronym for N or a N umber ) are created.

    
09.07.2018 / 13:58