Reputation: 77
I'm trying to plot the frequency of different hair colors in women with the HairEyeColor dataset. Example:
library(plotly)
freq <- HairEyeColor[,,2]
plot_ly(x = freq, type = 'bar')
I got the error-message: more elements in the method signature (2) than in the generic signature (1) for function ‘asJSON’
Upvotes: 1
Views: 231
Reputation: 1127
You could try this way
library(plotly)
freq <- HairEyeColor[,,2]
freq <- as.data.frame(freq)
attach(freq)
plot_ly(freq, x = ~ Hair, y = ~ Freq, type = 'bar')
I got the following graph. Don't knwo whether that was the one you were looking for
Upvotes: 2
Reputation: 3294
You could do:
library(plotly)
library(tidyverse)
HairEyeColor[,,2] %>%
as_tibble() %>%
group_by(Hair) %>%
summarise(freq = sum(n)) %>%
plot_ly(x = ~Hair, y = ~freq, type = "bar")
Upvotes: 1