'How do I use geom_bar to not take the frecuency of my class but another value?

Im trying to graph the number of bases (A,C,G,T) each of my viruses have on a single histogram.

library(readxl)
library(ggplot2)
Bases <- read_excel("/Users/******/Downloads/BASESCOVID2.xlsx")
data<- Bases
theme_set(theme_classic())
g <- ggplot(data, aes(Virus))
g + geom_bar(aes(fill=Class), width = 0.5) + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
  labs(title="Nucleotide Bases Comparison", 
       subtitle="Coronaviruses", 
       caption="N: Unknown")

On my 7th line of code instead of filling my graph with the frequency of Class I want to tell R how many of that Class there is, on another column.

Data structure:

enter image description here

Current graph: enter image description here



Solution 1:[1]

library(readxl)
library(ggplot2)
Bases <- read_excel("/Users/********/Downloads/BASESCOVID2.xlsx")
data<- Bases
ggplot(data,aes(x=Virus,y=Count,fill=Class)) + 
  geom_bar(stat="identity")+
  geom_text(aes(y=label_ypos,label=Count), vjust=1.6,
            color="white",size=3.5)+
scale_fill_brewer(palette = "Spectral")+
  theme(axis.text.x = element_text(angle=65, vjust=0.6))
  theme_classic()

I had to modify my excel file by adding a 4th column filled with ones that looks like this.

This is the result.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Struggling_Student