r - ggplot2 is incorrectly sorting the X axis of my graph -


i trying create plot of user login behavior 2 month period. used qplot function ggplot2 package, , following code

qplot(date_time, login_count, data=client_login_clean)

i plotted login_count on time shown below. unfortunately, y-axis, num_records sorted such first 5 tick marks on y-axis 1, 10, 106, 11, , 12, rather 1, 2, 3, 4, 5. let me know how fix this?

user logins on time

that's because, reason, login_count variable character vector. ggplot internally coerces character vectors factors, labels ordered alphabetically, , sorts axis according order.

i think know why happened: "num_records" value in login_count column, whole thing has been coerced character vector. delete element , use as.numeric, ordering should correct. opportunity read on data loading/generating process , make sure haven't made other mistakes. tiniest bugs can uncover massive problems never have noticed otherwise.

as side note, why should careful character-class variables , ggplot plotting. can save lot of headaches explicitly specifying factor ordering front.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -