-1

So, for my data, the default ggplot gave;

enter image description here

Now, i wish for my range of values on the y-axis to be; "0.5","1.0","1.5" to enable a better observation of the trend of the plots which seems to be between 0.8 and 1.0.

To do this, i added the code below to my plot;

scale_y_discrete(limits = c(0.5,1.5), breaks = c(0.5, 1.0, 1.5))

But instead of getting my desired result which is to visually eliminate 0 to 0.5 on the plot, i got;

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
Blessing
  • 3
  • 2
  • Perhaps you want to you ylim(0.8, 1) instead of scale _y?https://ggplot2.tidyverse.org/reference/lims.html – Susan Switzer Jun 22 '20 at 21:46
  • Some code an a reproducible example would be good: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Jun 23 '20 at 01:11

1 Answers1

0

Without a reproducible example, I've had to attempt to recreate your plot:

library(ggplot2)
library(ggpubr)

set.seed(69)
Regions <- rep(paste("Region", 1:10), each = 4)
Regions <- factor(Regions, levels = paste("Region", 1:10))
Index <- rep(c("HDI", "II", "HI", "EI"), 10)
Index <- factor(Index, levels = c("HDI", "II", "HI", "EI"))
Mean <- runif(40, .85, .95)
Upper <- Mean + 0.015
Lower <- Mean - 0.01
Upper[Index == "HI" | Index == "EI"] <- NA
Lower[Index == "HI" | Index == "EI"] <- NA

df <- data.frame(Regions, Index, Mean, Lower, Upper)

p <- ggplot(df, aes(Regions, Mean, fill = Index)) + 
  geom_col(position = "dodge", width = 0.8, colour = "#6b6f74") +
  geom_errorbar(aes(ymin = Lower, ymax = Upper), position = "dodge") +
  scale_fill_manual(values = c("#fae4ba", "#dba115", "#aba8a7", "#447ba4")) +
  theme_pubr() +
  theme(legend.position = "top") +
  labs(title = "Regional population distribution by social indexes",
       y = "Mean +- SD of Crude Rate")

p

enter image description here

And after all that, I've come to the conclusion that you were just looking for coord_cartesian:

p + coord_cartesian(ylim = c(0.75, 1.05))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • 1
    Thank you so much @Allan, that is exactly what i was looking for. My apologies for not pasting the code – Blessing Jun 22 '20 at 22:14