Last active
July 14, 2020 13:58
-
-
Save Ze1598/6dc148e4f74c7ddb72c8f80deb58243d to your computer and use it in GitHub Desktop.
Unpivot data with delimiters (R): count frequencies and plot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_counts <- unpivot_wide_data %>% | |
group_by(`Used Social Networks`) %>% | |
summarize(Frequency = n()) | |
# Order the data by descending order of the frequency | |
data_counts <- data_counts[ | |
order(data_counts$Frequency, decreasing = TRUE) | |
,] | |
# Order the X axis by the current order of the values in the "Frequency" column | |
fig <- plot_ly(data_counts) %>% | |
add_bars( | |
x = ~ `Used Social Networks`, | |
y = ~ Frequency) %>% | |
layout( | |
title = "Users of Social Networks", | |
xaxis = list( | |
title = "Social Networks", | |
categoryorder = "array", | |
categoryarray = data_counts$Frequency | |
), | |
yaxis = list(title = "Users") | |
) | |
fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment