Making a bar plot



Hi everyone, I'm new to R studio and I'm trying to make a bar graph plot with ggplot2. I have the "base" for the code, however im having a hard time figuring out what goes into certain parts. Here is a reprex of my dataset (also new to making a reprex) as well as the code im using. The error I'm encountering is with what to put for aes (x= y= and color)

        picoeukaryotes         sample
1           1834                Site 1
2           3139                Site 2
3           1361                Site 3
ggplot(picoeukaryotes, aes(x=axis1, y=axis2, color=dx)) +
  geom_point(shape =10, size =2)+
                     values = c("blue","red","black"),
                     breaks = c("Site 1","Site 2","Site 3"),
                     labels = c("1","2","3"))+
  labs(title = "Amount of Picoeukaryotes",
       y="Number of Species")+


It's hard to tell exactly from your code (I assume your data frame has headers/column names), but I think in this case your x would be whatever the column name is for the Site variable.

Check out this quick start to barplots in ggplot2:


Hi @livjos!

I added code formatting to your original post, which makes it easier to read what you posted (and, for instance, see how your data columns were supposed to align). I strongly encourage you to do this yourself in the future — you can read more about how code formatting works on this forum here: FAQ: How to make your code look nice? Markdown Formatting

(Tip: if you use the reprex package to process your code examples, it takes care of the formatting for you, and gives you a perfect, paste-ready chunk! :grin:)

A tiny note — you said you wanted to make a bar plot, but your code template is actually making a scatterplot (it has a geom_point() layer, instead of a geom_bar() or geom_col() layer). Hopefully you can adapt some of the very clear examples at mara's link to do what you want!


Omg, this guide totally helped me and I was able to get a plot. Thank you so much!


Oops, thank you! I have a base code for both. Thank you!