[R-br] Dificuldade com gráfico em ggplot2
Daniel Guimarães Tiezzi
dtiezzi em usp.br
Ter Fev 2 12:59:02 -02 2021
Bom dia
Seria algo assim?
df <- structure(list(Mês = c("Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez", "Total"), `2016` = c(209L, 3959L, 8668L, 5448L, 4198L, 4042L, 4602L, 6969L, 3336L, 8580L, 6036L, 352L, 56399L), `2017` = c(314L, 2740L, 2758L, 2424L, 4138L, 2030L, 280L, 4552L, 2509L, 2847L, 6322L, 179L, 31093L), `2018` = c(778L, 3968L, 3092L, 2357L, 1333L, 895L, 5489L, 3598L, 4072L, 5562L, 6218L, 115L, 37477L), `2019` = c(246L, 2353L, 2905L, 4563L, 2791L, 493L, 3197L, 6463L, 1375L, 5626L, 10443L, 138L, 40593L), `2020` = c(76L, 2685L, 2062L, 0L, 0L, 0L, 0L, 1408L, 1554L, 3831L, 4573L, 1104L, 17293L)), class = "data.frame", row.names = c(NA, -13L))
df
df_s <- as.data.frame(t(df[nrow(df),-1]))
colnames(df_s) <- 'total'
df_s$ano <- seq(2016, 2020)
df_s
library(ggplot2)
p0 <- ggplot(data = df_s, aes(y=stat(total), x = ano)) + geom_bar() + theme_minimal()
p0
df_l <- df[-nrow(df), c(1,6)]
colnames(df_l) <- c('m', 'val')
df_l
p1 <- ggplot(data = df_l, aes(x = m, y = val, group = 1)) + geom_line() + theme_minimal()
p1
----------------------------------------------------------------
Daniel Tiezzi, MD, PhD
Oncologia / Mastologia
Professor Associado - Livre Docente
Departamento de Ginecologia e Obstetrícia
Setor de Mastologia e Oncologia Ginecológica
Faculdade de Medicina de Ribeirão Preto - USP
Tel.: 16 3602-2488
https://github.com/dtiezzi <https://github.com/dtiezzi>
http://danieltiezzi.pro.br <http://danieltiezzi.pro.br/>e-mail: dtiezzi em usp.br
> On 2 Feb 2021, at 11:07, Olympio Neto por (R-br) <r-br em listas.c3sl.ufpr.br> wrote:
>
> structure(list(Mês = c("Jan", "Fev", "Mar", "Abr", "Mai", "Jun",
> "Jul", "Ago", "Set", "Out", "Nov", "Dez", "Total"), `2016` = c(209L,
> 3959L, 8668L, 5448L, 4198L, 4042L, 4602L, 6969L, 3336L, 8580L,
> 6036L, 352L, 56399L), `2017` = c(314L, 2740L, 2758L, 2424L, 4138L,
> 2030L, 280L, 4552L, 2509L, 2847L, 6322L, 179L, 31093L), `2018` = c(778L,
> 3968L, 3092L, 2357L, 1333L, 895L, 5489L, 3598L, 4072L, 5562L,
> 6218L, 115L, 37477L), `2019` = c(246L, 2353L, 2905L, 4563L, 2791L,
> 493L, 3197L, 6463L, 1375L, 5626L, 10443L, 138L, 40593L), `2020` = c(76L,
> 2685L, 2062L, 0L, 0L, 0L, 0L, 1408L, 1554L, 3831L, 4573L, 1104L,
> 17293L)), class = "data.frame", row.names = c(NA, -13L))
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20210202/b5df65a5/attachment.html>
Mais detalhes sobre a lista de discussão R-br