geom_bar issue in ggplot2 with xlim()
1
0
Entering edit mode
7 months ago
rj.rezwan ▴ 10

Hi, 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

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)

Can someone suggest how to bring the bars in the plot. here is the plot without bars

enter image description here

I will be grateful.

geom_bar ggplot2 statistics R • 374 views
ADD COMMENT

Login before adding your answer.

Traffic: 2197 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6