geom_errorbar gives error in display in faceted marplot ggplo2
up vote
0
down vote
favorite
I am struggling to find out the mistake I am making in trying to produce this barplot with standard deviation error bars. The result I get is of error bars not properly positioned (vertically, in my opinion) in my bars.
My dataset is
'data.Nema': 11 obs. of 6 variables:
$ STATION: Factor w/ 3 levels "FARO","ISLA D",..: 1 1 1 1 2 2 2 2 3 3 ...
$ SEASON : Factor w/ 4 levels "Summer15","Winter15",..: 1 3 2 4 1 3 2 4 1
$ N : int 5 3 5 3 5 3 5 3 5 3 ...
$ mean : num 2285 4419 795 1057 3694 ...
$ sd : num 511 1425 216 597 789 ...
$ se : num 256 1008 108 422 395 ...
my code is:
p4 <- ggplot(data=data.Nema, aes(x=STATION, y=mean, fill="Nematoda")) +
geom_bar(stat = "identity",position=position_dodge()) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)+
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
theme(strip.text.x = element_text(size = 8, colour = "black"))+
theme(axis.text=element_text(size = 8), axis.text.x=element_text(angle = 90, hjust = 1), axis.title.x = element_text(size = 8, vjust = 0.1),
axis.title.y = element_text(size = 9, vjust = 0.3), legend.position="bottom",legend.text=element_text(size=8), legend.title = element_text(size = 8)) + ylab(expression(paste("Individual numbers", " 10",cm^-2 ))) +
xlab("" ) +
geom_errorbar(aes(ymin = data.Nema$mean - sd,
ymax = data.Nema$mean + sd,
width = 0.1), position=position_dodge(0.9)) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)
plot(p4)

Thank you for your help
r ggplot2 errorbar
|
show 1 more comment
up vote
0
down vote
favorite
I am struggling to find out the mistake I am making in trying to produce this barplot with standard deviation error bars. The result I get is of error bars not properly positioned (vertically, in my opinion) in my bars.
My dataset is
'data.Nema': 11 obs. of 6 variables:
$ STATION: Factor w/ 3 levels "FARO","ISLA D",..: 1 1 1 1 2 2 2 2 3 3 ...
$ SEASON : Factor w/ 4 levels "Summer15","Winter15",..: 1 3 2 4 1 3 2 4 1
$ N : int 5 3 5 3 5 3 5 3 5 3 ...
$ mean : num 2285 4419 795 1057 3694 ...
$ sd : num 511 1425 216 597 789 ...
$ se : num 256 1008 108 422 395 ...
my code is:
p4 <- ggplot(data=data.Nema, aes(x=STATION, y=mean, fill="Nematoda")) +
geom_bar(stat = "identity",position=position_dodge()) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)+
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
theme(strip.text.x = element_text(size = 8, colour = "black"))+
theme(axis.text=element_text(size = 8), axis.text.x=element_text(angle = 90, hjust = 1), axis.title.x = element_text(size = 8, vjust = 0.1),
axis.title.y = element_text(size = 9, vjust = 0.3), legend.position="bottom",legend.text=element_text(size=8), legend.title = element_text(size = 8)) + ylab(expression(paste("Individual numbers", " 10",cm^-2 ))) +
xlab("" ) +
geom_errorbar(aes(ymin = data.Nema$mean - sd,
ymax = data.Nema$mean + sd,
width = 0.1), position=position_dodge(0.9)) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)
plot(p4)

Thank you for your help
r ggplot2 errorbar
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr(),head()or screenshot)? You can use thereprexanddatapastapackages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 8 at 3:05
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am struggling to find out the mistake I am making in trying to produce this barplot with standard deviation error bars. The result I get is of error bars not properly positioned (vertically, in my opinion) in my bars.
My dataset is
'data.Nema': 11 obs. of 6 variables:
$ STATION: Factor w/ 3 levels "FARO","ISLA D",..: 1 1 1 1 2 2 2 2 3 3 ...
$ SEASON : Factor w/ 4 levels "Summer15","Winter15",..: 1 3 2 4 1 3 2 4 1
$ N : int 5 3 5 3 5 3 5 3 5 3 ...
$ mean : num 2285 4419 795 1057 3694 ...
$ sd : num 511 1425 216 597 789 ...
$ se : num 256 1008 108 422 395 ...
my code is:
p4 <- ggplot(data=data.Nema, aes(x=STATION, y=mean, fill="Nematoda")) +
geom_bar(stat = "identity",position=position_dodge()) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)+
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
theme(strip.text.x = element_text(size = 8, colour = "black"))+
theme(axis.text=element_text(size = 8), axis.text.x=element_text(angle = 90, hjust = 1), axis.title.x = element_text(size = 8, vjust = 0.1),
axis.title.y = element_text(size = 9, vjust = 0.3), legend.position="bottom",legend.text=element_text(size=8), legend.title = element_text(size = 8)) + ylab(expression(paste("Individual numbers", " 10",cm^-2 ))) +
xlab("" ) +
geom_errorbar(aes(ymin = data.Nema$mean - sd,
ymax = data.Nema$mean + sd,
width = 0.1), position=position_dodge(0.9)) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)
plot(p4)

Thank you for your help
r ggplot2 errorbar
I am struggling to find out the mistake I am making in trying to produce this barplot with standard deviation error bars. The result I get is of error bars not properly positioned (vertically, in my opinion) in my bars.
My dataset is
'data.Nema': 11 obs. of 6 variables:
$ STATION: Factor w/ 3 levels "FARO","ISLA D",..: 1 1 1 1 2 2 2 2 3 3 ...
$ SEASON : Factor w/ 4 levels "Summer15","Winter15",..: 1 3 2 4 1 3 2 4 1
$ N : int 5 3 5 3 5 3 5 3 5 3 ...
$ mean : num 2285 4419 795 1057 3694 ...
$ sd : num 511 1425 216 597 789 ...
$ se : num 256 1008 108 422 395 ...
my code is:
p4 <- ggplot(data=data.Nema, aes(x=STATION, y=mean, fill="Nematoda")) +
geom_bar(stat = "identity",position=position_dodge()) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)+
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
theme(strip.text.x = element_text(size = 8, colour = "black"))+
theme(axis.text=element_text(size = 8), axis.text.x=element_text(angle = 90, hjust = 1), axis.title.x = element_text(size = 8, vjust = 0.1),
axis.title.y = element_text(size = 9, vjust = 0.3), legend.position="bottom",legend.text=element_text(size=8), legend.title = element_text(size = 8)) + ylab(expression(paste("Individual numbers", " 10",cm^-2 ))) +
xlab("" ) +
geom_errorbar(aes(ymin = data.Nema$mean - sd,
ymax = data.Nema$mean + sd,
width = 0.1), position=position_dodge(0.9)) +
facet_wrap(facets = ~data.Nema$SEASON, ncol =3)
plot(p4)

Thank you for your help
r ggplot2 errorbar
r ggplot2 errorbar
edited Nov 8 at 16:03
aosmith
20.3k43965
20.3k43965
asked Nov 7 at 20:32
Francesca Pasotti
61
61
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr(),head()or screenshot)? You can use thereprexanddatapastapackages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 8 at 3:05
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06
|
show 1 more comment
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr(),head()or screenshot)? You can use thereprexanddatapastapackages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 8 at 3:05
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str(), head() or screenshot)? You can use the reprex and datapasta packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 8 at 3:05
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str(), head() or screenshot)? You can use the reprex and datapasta packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 8 at 3:05
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197371%2fgeom-errorbar-gives-error-in-display-in-faceted-marplot-ggplo2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str(),head()or screenshot)? You can use thereprexanddatapastapackages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 8 at 3:05
structure(list(STATION = structure(c(1L, 1L, 1L, 1L), .Label = c("FARO", "ISLA D", "CREEK"), class = "factor"), SEASON = structure(c(1L, 3L, 2L, 4L), .Label = c("Summer15", "Winter15", "Spring15", "Spring16" ), class = "factor"), N = c(5L, 3L, 5L, 3L), mean = c(2284.93355351105, 4419.28127703075, 795.2, 1056.66666666667), sd = c(511.394995921795, 1425.24532727231, 216.172847508654, 596.913170681744), se = c(255.697497960898, 1007.80063576869, 108.086423754327, 422.081350768624)), .Names = c("STATION", "SEASON", "N", "mean", "sd", "se"), row.names = c(NA, 4L), class = "data.frame")
– Francesca Pasotti
Nov 8 at 10:41
Is this what you asked? Sorry, I was not aware of this requirement. Thank you for willing to help!
– Francesca Pasotti
Nov 8 at 10:41
Yes, that's exactly the kind of info you need. You can use the edit button to add the data to your question.
– aosmith
Nov 8 at 16:05
I think your problem is with using dollar sign notation along with facets. See here for a full explanation. I believe this won't be a problem in future (current?) versions of ggplot2, but you still should refer directly to the variable names when using ggplot2.
– aosmith
Nov 8 at 16:06