How to change bar graph border size in ggplot2

Asked

Viewed 255 times

1

I have a bar graph on the R made with the function geom_col. I would like to decrease the border size, because it is not showing the chart fill. I tried using the argument width, but is only changing the size of the padding and has not solved the problem.

How’s the chart coming along:

inserir a descrição da imagem aqui

Code I am using:

suppressPackageStartupMessages({
  library(tidyverse)
  library(zoo)
})

url <- httr::GET("https://xx9p7hp1p7.execute-api.us-east-1.amazonaws.com/prod/PortalGeral",
                 httr::add_headers("X-Parse-Application-Id" =
                                     "unAFkcaNDeXajurGB7LChj8SgQYS2ptm")) %>%
  httr::content() %>%
  '[['("results") %>%
  '[['(1) %>%
  '[['("arquivo") %>%
  '[['("url")

dados <- utils::read.csv2(url, stringsAsFactors = FALSE, fileEncoding = "latin1")
dados$data <- lubridate::as_date(dados$data)

dados <- dados %>%
  filter(data > as.Date("2020-02-29"))

rm(url)

dados %>%
  mutate(mm7dCasos = rollmean(casosNovos, 7, fill = list(NA, NULL, NA), align = "right")) %>%
  filter(data > "2020-03-14") %>%
  ggplot() +
  geom_col(aes(x = data, y = casosNovos), na.rm = TRUE, color = "black", fill = "white", width = 0.75) +
  geom_line(aes(x = data, y = mm7dCasos), colour = "#FF6347", size = 0.4) +
  labs(x = "", y = "") +
  ggtitle("Variação diária de novos casos confirmados - Brasil", "(MM7d)") +
  coord_cartesian(ylim = c(0, 1000)) +
  scale_x_date(date_labels = "%b %d", date_breaks = "2 week") +
  theme(text = element_text(size = 10), axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~estado, nrow = 3)
  • Unable to find "rollmean"

  • Sorry, the package was pre-loaded in my R, already includes it in the code.

  • Have you seen the result remove color of geom_col?

  • If I remove the color, the ggplot2 only leaves without the edge.

  • 1

    Try to change the argument size in the geom_col

1 answer

3


For this just add the argument size in function geom_col. The argument widthchanges the size of the fill, while the size changes the border size.

New code:

dados %>%
  mutate(mm7dCasos = rollmean(casosNovos, 7, fill = list(NA, NULL, NA), align = "right")) %>%
  filter(data > "2020-03-14") %>%
  ggplot() +
  geom_col(aes(x = data, y = casosNovos), na.rm = TRUE, color = "black", fill = "white", size = 0.1, width = 0.75) +
  geom_line(aes(x = data, y = mm7dCasos), colour = "#FF6347", size = 0.4) +
  labs(x = "", y = "") +
  ggtitle("Variação diária de novos casos confirmados - Brasil", "(MM7d)") +
  coord_cartesian(ylim = c(0, 1000)) +
  scale_x_date(date_labels = "%b %d", date_breaks = "2 week") +
  theme(text = element_text(size = 10), axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~estado, nrow = 3)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.