New to R coding, new to coding in general

Hi @Dan_Almeida , welcome.

Is better if you put a reproducible example of data, see this link for that.

You need something like that, and the data is this order for make more easy:

df <- data.frame(brands=c('Merc','Fiat','Hornet','Merc','Fiat','Hornet'),
                 cnt=c(20,15,12,10,13,7),
                 type=c('A','B','C','C','A','B'),
                 percentage=c(25.974026,19.480519,15.584416,12.987013,16.883117,9.090909))

tibble(df) %>% 
  ggplot(aes(
    x = brands,
    y = percentage,
    fill = type,
    label = percentage)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values=c('#CA0067','#F6BB00','#00C20D'))+
  geom_text(position = position_stack(vjust = .5), 
    aes(x = brands,
        y = percentage,
        label = paste0(round(percentage,2),"%"))) +
  labs(title='put title',
       caption = 'caption',
       y=' ')+
  coord_flip()+ # for rotate the plot
  theme_classic()

In a before opportunity Im make the same quenstions and other user help me.
Im make better the code for you.

1 Like