I need to create a scatterplot of two continuous variables (prop_segundos, prop_primeiros), but ggplot2 removes all rows because either one or the other has NAs. This is my reprex:
tribble_paste(d)
tibble::tribble(
~prop, ~rank, ~prop_segundos, ~votos_segundo, ~dif, ~dif_pct, ~prop_primeiros,
0.469359963685883, 2L, 0.469359963685883, 1034L, NA, NA, NA,
0.530640036314117, 1L, NA, NA, 135L, 0.0612800726282343, 0.530640036314117,
0.0290898886914227, 4L, NA, NA, NA, NA, NA,
0.137031147694322, 3L, NA, NA, NA, NA, NA,
0.214947151809934, 2L, 0.214947151809934, 2298L, 833L, 0.0779160041156113, NA,
0.618931811804321, 1L, NA, NA, 4319L, 0.403984659994388, 0.618931811804321
)
And this is the ggplot I'm trying to run:
ggplot(
data = d,
aes(x = prop_primeiros, y = prop_segundos)) +
geom_point() +
geom_smooth() +
stat_smooth(
method = "lm",
color = "#C42126",
na.rm = TRUE,
se = FALSE) +
scale_y_continuous(limits=c(0,1)) +
scale_x_continuous(limits=c(0,1)) +
xlab("Porcentagem dos votos do primeiro") +
ylab("Porcentagem dos votos do segundo") +
ggtitle("Relação % primeiro-segundo nos casos não judicializados")
##Then I get this error message:
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
Warning messages:
1: Removed 6 rows containing non-finite values (stat_smooth).
2: Removed 6 rows containing missing values (geom_point).
I get a plot with the proper labels and title, but no observations. Is there any way of telling ggplot to ignore missing values and plot only avaluable observations? Removing rows with NAs is no good, otherwise all my obs. are removed.