Hi!
I have a problem with geom_line(), when I use it, it doesn't work. I can use goem_point or else but this one does not work, what can I do? Is there something else I can try?
Thank you a lot.
Hi!
I have a problem with geom_line(), when I use it, it doesn't work. I can use goem_point or else but this one does not work, what can I do? Is there something else I can try?
Thank you a lot.
Here is a simple example of using geom_line that works for me. Does it work for you? Can you provide an example that does not work for you?
library(ggplot2)
DF <- data.frame(Xval = 1:5, Yval = 11:15)
ggplot(DF, aes(Xval, Yval)) + geom_line()
I created the data frame with values on y and word on x as:
a <- data.frame(words, values, lettersAsFactors=TRUE)
then I write:
ggplot(data = a, aes(x = words, y = values))+ geom_point() + geom_line() + NULL
when I run this it only draw the points and not the line...I do not know why.
You might want to try creating the line first and then adding the points afterwards. You could also try leaving out the NULL you added at the end.
Because you are using factors, which is different from @FJCC 's numeric vars. From what I understand from the documentary, geom_line()
attempts to draw a line at each factor level. Specifying that they all belong to the same group does the trick.
Does the code below solve your problem?
DF <- data.frame(Xval = as_factor(LETTERS[1:5]), Yval = 11:15)
ggplot(DF, aes(x = Xval, y = Yval, group = 1)) + geom_point() + geom_line()
JW
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.