Error message popped up

Hi,
I am having problem with ggplot2. When I type

ggplot(Data,
       aes(x = Season, y = Aeromonas)) +
  geom_boxplot(fill='lightblue', color='blue') +
  geom_point(color='darkblue')

a perfect graph showed up.

But when I type

ggplot(Data,
       aes(x = Water type, y = Aeromonas)) +
  geom_boxplot(fill='lightblue', color='blue') +
  geom_point(color='darkblue')

This error message popped up

Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?

Please help me. What's the problem?

I'm not sure what that error message means without being able to recreate it through a reprex but if you copied that code exactly, you need `` around Water Type, so it should be:

ggplot(Data,
aes(x = `Water type`, y = Aeromonas)) +
geom_boxplot(fill='lightblue', color='blue') +
geom_point(color='darkblue')

If that doesn't work, look here to make a reprex:

3 Likes

Thanks dlsweet. I tried with your code. Now instead of dividing my water type into 4 different groups, it makes one single group. Like this,

image

Can you create a reprex?

2 Likes

Are you sure you used back ticks and not single quotes around Water type? Back ticks are on the same key as the tilde on my keyboard.

1 Like

No. I don't know how to create a reprex.

Yes. I just copied and pasted the code and ran. Nothing worked.

Hi there Sultana! Creating a reprex (short for reproducible example) is very easy!

First, install the reprex package: install.packages("reprex") and load its library: library(reprex)

Then, follow the instructions here to create the reprex. The link I provided includes a discussion of how to add your data to the reprex, which will probably be key to helping you get the right eyes on this.

A reprex will ensure we're all looking at the same data and code, which helps us to help you!

One more thought: you mentioned wanting to see four different groups in your boxplot. It sounds like you may be interested in either faceting or grouping by season. If that's the case, you may want to consider (for example) using facet_wrap() with your Season variable.

I hope this helps!

1 Like

Hi Katherine,

Thanks for this help. It helped.