r - Discrete value supplied to continuous scale - Dataset does not have any factors -
i know has been asked, not understand why keep getting discrete value supplied continuous scale
error when trying customize axis on graph.
on questions have read said happened because of variables on dataset defined factors, whic not happen in case.
df <- data.frame(grupo = c('tratado', 'controle', 'tratado', 'controle', 'tratado','controle'), uf = c('sp','mg','mg','sp','ba','ba'), prop = c(0.166, 0.161, 0.121, 0.112, 0.092,0.084)) ggplot(df,aes(x = reorder(uf,prop), y = prop)) + geom_bar(aes(fill = grupo), position = 'dodge', stat = 'identity') + coord_flip() + theme_classic() + labs(x = 'importância na amostra', y = 'uf') + scale_x_continuous(labels = scales::percent)
it's best think of coord_flip
visual transformation gets applied right @ end of whole plot building process. prop
y
variable, apply scale_y_continuous
it, , right @ end coord_flip
applied , prop
moves x-axis. fix use scale_y
instead of scale_x
:
ggplot(df,aes(x = reorder(uf,prop), y = prop)) + geom_bar(aes(fill = grupo), position = 'dodge', stat = 'identity') + coord_flip() + theme_classic() + labs(x = 'importância na amostra', y = 'uf') + scale_y_continuous(labels = scales::percent)
Comments
Post a Comment