It shows "Error in as.numeric(Weight) - sd : non-numeric argument to binary operator", but I already make the weight numeric........

library(ggplot2)
ggplot(mydata,aes(x=Temperature,y=Weight))+geom_bar(stat="identity", data =mydata,fill = NA, color = "black")+
geom_jitter( position = position_jitter(0.2),
color = "black") +
geom_errorbar(
aes(ymin = as.numeric(Weight)-sd, ymax = as.numeric(Weight)+sd),
data = mydata, width = 0.2)

Generally you are well advised to seperate data transformation code and charting code. Your case is a good example why.
Change weights in mydata before starting to ggplot.

Hello! I tried to change it before ggplot, but it shows a similar message......

mydata$Weight = as.numeric(mydata$Weight)
library(ggplot2)
ggplot(mydata,aes(x=Temperature,y=Weight))+geom_bar(stat="identity", data =mydata,fill = NA, color = "black")+
geom_jitter( position = position_jitter(0.2),
color = "black") +
geom_errorbar(
aes(ymin = Weight-sd, ymax = Weight+sd),
data = mydata, width = 0.2)

My other advice is to reduce needless repetition. Within your ggplot ting code mydata is written out 3 times, as you dont use other data, having it once the first time is enough.

If you are stuck and want more specific help please try to make a reproducible example of your problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.