Graph error with package ggplot2 and function sumarySE

Asked

Viewed 30 times

3

I seek your assistance in solving some problems in constructing a graph with average and standard error in R with the ggplot2 package and summarySE function.

In my work I evaluate the effect of competition by resource between two species of aquatic vertebrates with different sizes p/g, through the variables PV displacement and PH displacement. I have found some errors for the script execution, I present them below.

I appreciate the cooperation of all. I hope this post can help others.

Mistakes:

Error1:
gmed <- read.csv("https://drive.google.com/file/d/1X7FEhxjxAVBD-9LB6UrRUd2aMtjcwnyR/view", header = TRUE,sep = ";")

Warning message:
In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
EOF within quoted string

Error 2:
gpv <- summarySE(gmed, measurevar="PV", groupvars=c("INT"))
Error in FUN(X[[i]], ...) : objeto 'INT' não encontrado

chart script :

gmed <- read.csv("https://drive.google.com/file/d/1X7FEhxjxAVBD-9LB6UrRUd2aMtjcwnyR/view", header = TRUE,sep = ";")

require(Rmisc)
require(ggplot2)

gpv <- summarySE(gmed, measurevar="PV", groupvars=c("INT"))

grafic.gpv <- ggplot(gpv, aes(x=INT, y=PV, fill=INT)) +
  scale_x_discrete(limits=c("S", "P", "G", "F")) + 
  geom_dotplot(binwidth= 0.5, binaxis="y", stackdir = "center") +
  geom_errorbar(aes(ymin=PV-se, ymax=PV+se), width=0.25, size=0.25) +
  labs(x="Tratamentos", y="Posição Vertical (cm)") +
  geom_text(aes(label=paste("N", "==",N,sep = "")), parse = TRUE, y=c(17.5, 15, 15, 22.5)) +
  geom_point(aes(y=PV), size=1, show.legend = F) +
  theme_bw () +
  scale_fill_grey(start=0.25, end=0.75)

grafic.gpv

1 answer

3

You are misreading the file, a correct way is as follows:

google_id <- "1X7FEhxjxAVBD-9LB6UrRUd2aMtjcwnyR"
google_file <- sprintf("https://docs.google.com/uc?id=%s&export=download", google_id)
gmed <- read.csv2(google_file)

str(gmed)
#'data.frame':  60083 obs. of  5 variables:
# $ ID     : int  6 6 6 6 6 6 6 6 6 6 ...
# $ INT    : chr  "S" "S" "S" "S" ...
# $ Tamanho: chr  "P" "P" "P" "P" ...
# $ PV     : num  0 0 0 0 0 0 0 0 0 0 ...
# $ PH     : num  16 16 16 16 16 16 16 16 16 16 ...

After this, the rest of the script, summarySE and graphical instructions, works smoothly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.