Home > Mobile >  Scaling problem when plotting a graph in R
Scaling problem when plotting a graph in R

Time:12-23

I am trying to generate a bar graph in R, but as the y-axis values ​​are very close, there is no difference in the graph.
Can someone help me?

This is the data I use to generate the chart.

rede <- c("Wifi", "Wifi(AB)", "Wifi(AB)   4G(AB)", "Wifi(AB)   4G(B)", "4G(AB)")
disp <- c(0.9981663483026838, 0.9979983253954591, 0.9983305230561498, 0.9981898613052699, 0.9980460877265795)
down <- c(16.062788868489800, 17.534669535778500, 14.624618028127900, 15.85681496583588, 17.116271515163100)
dados <- data.frame("Ref" = rede, "Disponibilidade" = disp, "Downtime" = down)

ggplot(dados)  
aes(
x = Ref,
fill = Disponibilidade,
weight = Disponibilidade
)  
geom_bar(position = "fill")  
scale_fill_viridis_c(option = "plasma", direction = 1)  
labs(
x = "Redes",
y = "Valores",
title = "Gráfico Disponibilidade"
)  
theme_minimal()  
theme(
plot.title = element_text(size = 18L,
                      face = "bold",
                      hjust = 0.5)
)

Graph

CodePudding user response:

As others mentioned in the comments, it's unclear what exactly you are looking for, but you could do something like this (as @JonathanV.Solórzano recommended with using coord_cartesian).

library(ggplot2) 

ggplot(dados)  
  aes(
    x = Ref,
    y = Disponibilidade,
    fill = Disponibilidade,
    weight = Disponibilidade
  )  
  geom_col()  
  scale_fill_viridis_c(option = "plasma", direction = 1)  
  coord_cartesian(ylim = c(min(dados$Disponibilidade), max(dados$Disponibilidade)))  
  labs(x = "Redes",
       y = "Valores",
       title = "Gráfico Disponibilidade")  
  theme_minimal()  
  theme(plot.title = element_text(size = 18L,
                                  face = "bold",
                                  hjust = 0.5))

Output

enter image description here

Alternative with geom_bar (which produces the same output as above)

ggplot(dados)  
  aes(
    x = Ref,
    fill = Disponibilidade,
    weight = Disponibilidade
  )  
  geom_bar()  
  scale_fill_viridis_c(option = "plasma", direction = 1)  
  coord_cartesian(ylim = c(min(dados$Disponibilidade), max(dados$Disponibilidade)))  
  labs(x = "Redes",
       y = "Valores",
       title = "Gráfico Disponibilidade")  
  theme_minimal()  
  theme(plot.title = element_text(size = 18L,
                                  face = "bold",
                                  hjust = 0.5))
  • Related