首页 > 解决方案 > Plotting densities with a summary data frame

问题描述

I have data from a bicycle rental service in NYC for a quarter. I have two user types - Customers and Subscribers and have created a variable called trip.type which can be "long", "avg" or "short". I created a summary data frame that has the counts for trip.type by user.type. However, we have far more subscribers than customers. So I would like to look at a density / percentage plot vs. just raw counts. How do I do this? Thank you so much. I am using ggplot2. Also, am a newbie, so sorry if this is too elementary a question.

DF <- data.frame(User.Type = rep(c("Unknown", "Customer", "Subscriber"), each = 4),
                 trip.type = rep(c("Avg", "long", "Short", "Unknown"), 3),
                 num_trips = c(891, 3817, 31, 77, 4123, 20888, 1378, 388, 266299, 225671, 203048, 734))

What I want is to plot the trip.types as percentages of the total number of users per User.Type instead of counts.

标签: rggplot2geom-bar

解决方案


推荐阅读