Home > Back-end >  R ggplot only shows one bar
R ggplot only shows one bar

Time:03-29

I am just starting to work with R, so apologies if my question is too basic, I have an excel sheet , here's the link: enter image description here

can anyone help how to fix this? Thanks

CodePudding user response:

First

Your question can be better formulated, please read how to ask a good question and how to create a minimal example to understand the basics of a workable question.

Also, in R, you have a very good tool for creating reproducible examples: the reprex package

Also, I would not download anything from a given link in a random question in StackOverflow, and neither should you.

Try

Execute this code in your computer, and see if it helps you understand how ggplot works:

library(ggplot2) # load ggplot
mpg # let's look at a 'mpg' data included in the ggplot package

# Now, a simple bar plot
ggplot(mpg, aes(x = fl))  
  geom_bar()

We use the mpg data as the data for our figure, and we set the x-axis to be the fl column of that data. Finally, we "add" a bar plot to the figure. By default, the bar plot will plot the count of the different values present in the column you passed as x-axis.

CodePudding user response:

I can't see your uploaded image with the excel sheet screenshot.

My guess would be using quotation marks instead of backticks. Try running this code:

ggplot(data = ZOTU, aes(x = `OTU ID`))   geom_bar()
  • Related