I am using very simple data to make a bar plot
in ggplot2
. but when I use the xlim()
ggplot2 in R. It makes the plot wut without bars in it. Could someone help me or guide why the bars are not being produced by ggplot2
Can someone suggest how to bring the bars in the plot. here is the plot without bars. I will be grateful to you.
here is the code
library(ggplot2)
library(readxl)
mapping <- read_excel("/Users/tariqr/Desktop/haplotypecalling/mapping_percentage.xlsx", sheet = "Sheet3", col_names = TRUE)
head(mapping)
varieties percentage
<chr> <dbl>
1 beauty_9 99.1
2 beauty_8 99.1
3 beauty_7 99.0
4 beauty_64 99.2
5 beauty_63 96.9
6 beauty_62 99.2
ggplot(mapping, aes(x = percentage, y = varieties)) +
geom_bar(stat = "identity", fill = "#99FF00", color = "purple") +
geom_text(aes(label = sprintf("%.2f%%", percentage)),
hjust = -0.2, size = 3, color = "black") + # Add text labels
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Mapping Percentage", x = "Mapping", y = "Varieties") +
scale_x_continuous(breaks = seq(96.5, 100, by = 0.5),
labels = paste0(seq(96.5, 100, by = 0.5), "%")) +
xlim(96.5, 100)
enter image description here
New contributor
Rezwan_Tariq is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.