Search code examples
rggplot2bar-chartreadxl

R ggplot only shows one bar


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: https://file.io/LfsAOdDCVnFq

where I am trying to plot a simple bar plot as follows:

X = I want it to be my sample names , the column called OTU ID in the file Y = I want it to be the sum of my variables for each sample, column called Sum ZOTUs in the file

so far, I have installed and called library of ggplot2 and tried to plot my data frame but when I do that it only shows one bar, and I don't know what is wrong

install.packages("readxl")
install.packages("ggplot2")

library(readxl)
library(ggplot2)

ZOTU <- read_excel(file.choose())

ggplot(data=ZOTU, aes(x="OTU ID")) + geom_bar ()

and it shows the plot below:

enter image description here

can anyone help how to fix this? Thanks


Solution

  • 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()