Reputation: 61
so I am trying to ggplot scatter plot with x-axis as the population which is current_votes, and y-axis as the percentage of votes for the population, colored by the candidate, either Joe Biden, or Trump. However, the number of points are all bunched up together at the top. How can I make it so that the points are evenly spread out if there are too many points?
scatter_c <- function(new_data) {
f <- ggplot(data = new_data, aes(x = percentage_votes, y = current_votes, color = candidate)) +
geom_point() +
scale_color_manual(
values = c("Donald Trump" = alpha("blue",0.3), "Joe Biden" = alpha("red",0.3))
) +
coord_flip()
return(f)
}
scatter_c(data_4)
Upvotes: 0
Views: 371
Reputation: 7858
Have you tried:
scatter_c <- function(new_data) {
ggplot(data = new_data, aes(x = current_votes, y = percentage_votes, color = candidate)) +
geom_point() +
scale_color_manual(
values = c("Donald Trump" = alpha("blue",0.3), "Joe Biden" = alpha("red",0.3))
) +
scale_x_log10()
}
library(ggplot2)
scatter_c(data_4)
I've removed coord_flip
and simply inverted x
and y
in aes
. Then I've used scae_x_log10
to get the expected result.
Just as a suggestion...
The perfect charts depends on what the goal of you analysis is. In this graph you are mixing percentages between each other...
Also, aren't republicans usually red and democrats blue?
Upvotes: 2