Nevedha Ayyanar
Nevedha Ayyanar

Reputation: 865

Is it possible to create single stacked column chart using plotly in R

I am having a dataframe.

    Frequency <- data.frame(Type = c("Quarterly", "halfyearly", "Yearly", "Weekly", "Other"), 
Count = c(45, 13, 3, 18, 21))

This is the expected output

enter image description here

Is it possbile to achieve this using plot_ly() function in R?

Can anyone suggest a suitable solution to achieve this. Thanks in advance!!!

Upvotes: 1

Views: 546

Answers (1)

Sergio Romero
Sergio Romero

Reputation: 368

Something like this? I had to add a column named "id" just to map it to the x axis, but I think it more or less looks like what you want.

enter image description here

Frequency %>% 
    mutate(id = as.factor(1)) %>% 
    plot_ly(
    x = ~ id,
    y = ~ Count,
    color = ~Type,
    type = 'bar'
) %>% 
    layout(yaxis = list(title = 'Count'), barmode = 'stack')

Upvotes: 1

Related Questions