I would like to recreate my ggplot barchart with plotly to make it interactive. However, I’m not able to get the y axis to be my desired variable and instead get the following error: Error in eval(expr, data, expr_env) :
object ‘genome_size_in_Mb’ not found.
My data:
dput():
structure(list(Subgroups = c("Jessenii", "fluorescens", "fluorescens",
"gessardii", "gessardii", "fragi", "fragi"), `Species Name + Strain` = c("Pseudomonas umsongensis",
"Pseudomonas fluorescens", "Pseudomonas extremaustralis", "Pseudomonas sp.",
"Pseudomonas fluorescens", "Pseudomonas psychrophila", "Pseudomonas taetrolens"
), Strain = c("GO16", "SBW25", "DSM17835", "Ag1", "R8", "HA4",
"LMG2336"), `refseq assembly` = c("GCF_008824165.1", "GCF_000009225.2",
"GCF_900102035.1", "GCF_000006765.1", "GCF_000297195.3", "GCF_000282975.1",
"GCF_900104825.1"), genome_size_in_Mb = c(7.4, 6.7, 6.7, 6.3,
7, 5.2, 4.9), `chromosome number` = c("2", "1", "1", "1", "1",
"-", "-"), `GC content` = c(59, 60.5, 60.5, 66.5, 61, 56.5, 58
), `Number of CDS genes` = c(6441, 5974, 6000, 5572, 6307, 4666,
4360), `Genes number` = c(6698, 6154, 6228, 6708, 6440, 4823,
4507)), row.names = c(NA, -7L), class = c("tbl_df", "tbl", "data.frame"
))
The ggplot chart code:
ggplot(
data = dba,
aes(x = forcats::fct_inorder(Strain),
y = genome_size_in_Mb,
fill = Subgroups)
) +
geom_bar(
position = "dodge",
stat = "identity",
width = 0.5
) +
scale_x_discrete(guide = guide_axis(angle = 90)) +
labs(title = "Genome Sizes Across Strains", x = "Strain", y = "Genome Size in Mb")
Follwing Plotlys example online
library(plotly)
library(dplyr)
fig1 <- db
fig1 <- fig %>% count(Strain, Subgroups)
fig1 <- fig %>% plot_ly(x = ~Strain, y = ~n, color = ~Subgroups)
print(fig1)