1

I have three y values corresponding to three x values. I just want to have a line graph between these three dots

g <- c("1","2","3")
i <- c(181.83,178.74,152.02)
df <- data.frame(g,i)
p <- ggplot(df, aes(x=g, y=i)) + geom_line() + geom_point()

Using this I get this:

enter image description here

First of all why does my geom_line() not work? After that I have:

se <- c(22.95,22.72,19.2)
p + geom_errorbar(aes(ymin=se,ymax=se))

And what I get is:

enter image description here

Why are my errorbars not centered around the data points? Why are they smushed to the bottom? Why do they seem horizontal? What can I do to fix this?

2
  • You can fix the first problem with adding group = 1 like this ggplot(df, aes(x = g, y = i, group = 1)) + geom_line() + geom_point() Commented Mar 23, 2019 at 17:36
  • Thank you so much! Should I edit out that part of the question because it's resolved? Commented Mar 23, 2019 at 17:46

1 Answer 1

2

Alright I figured it out: the ymin and ymax arguments are telling where the error line starts and ends quite literally, so you can't just put the real standard error value and expect ggplot2 to figure out where will this error line be centered. So you have to specify it as:

geom_errobar(aes(ymin = i - se, ymax = i + se))

And finally you get:

enter image description here

Hope it helps others as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.