0

Image of two graphs combined together:

enter image description here

I am currently attempting to make a ggplot with a boxplot and a path plot on the same image, the path plot is supposed to intersect with the median areas of the boxplot itself. For some reason the path plot is stretching far off where it is meant to be. I'm not sure what is causing this error. I have pasted all of the relevant code below. I've tried messing with the language in the ggplot area but nothing seems to fix this.

Bottom <- na.omit(subset.data.frame(Chronosequence, Chronosequence$vegetation_zone == "bottom"))
Transition <- na.omit(subset.data.frame(Chronosequence, Chronosequence$vegetation_zone == "transition"))
Edge <- na.omit(subset.data.frame(Chronosequence, Chronosequence$vegetation_zone == "edge"))



EdgeMean <- (Edge) %>% group_by(time_since) %>% 
  summarize(average = median(sum_of_non_native_cover_automatically_calculated)) %>%
  ungroup()


#### Plotting####
boxplot(Edge$sum_of_non_native_cover_automatically_calculated ~ Edge$time_since,
        xlab="Years Since Restoration Finished",
        ylab="Percent Cover of Non-Native Species")

ggplot() +
  geom_boxplot(mapping = aes(
    factor(x = Edge$time_since), y = Edge$sum_of_non_native_cover_automatically_calculated))+
  geom_path(mapping = aes(x= EdgeMean$time_since, y=EdgeMean$average)) 
 
2
  • 5
    In geom_boxplot() you are converting Edge$time_since into a factor. In geom_path, your are using the original values of Edge$time_since. You can't mix those two on the same axis and get a coherent plot. Please post a little sample data so it's easy to construct your plot. Commented Dec 11 at 2:15
  • 1
    Also, in subset you should remove the data.frame name from the filter condition. Keep the column name, subset(Chronosequence, vegetation_zone == "transition") is much better. Commented Dec 11 at 6:25

0

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.