Reputation: 865
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
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
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.
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