plotting NA on a ggplot scatter plot with weighted points

时间:2016-02-12 19:23:28

标签: r ggplot2

I'm plotting the following data:

  UKPRN    Subject    Total.number easting northing
1 10033225 Computing  NA           516857   209364
2 10035012 Computing  NA           337767   402199
3 10000571 Computing  NA           369406   163887
4 10034119 Computing  NA           567497   193951
5 10007140 Computing  7            407643   287149
6 10007140 Computing  5            407643   287149

I want to keep the NA data on the map, placing it as a cross, whilst plotting the numbered values as circles with a size. I use:

ggplot(map_data, aes(easting, northing, size = Total.number)) +
  geom_point(alpha = 2/3)

But the NA values aren't mapped. Any idea how I do this?

Warning message:
Removed 66 rows containing missing values (geom_point).

1 个答案:

答案 0 :(得分:2)

You could add another geom_point layer only including the NA values:

ggplot() +
  geom_point(data=map_data, aes(easting, northing, size = Total.number), alpha = 2/3) +
  geom_point(data=map_data[is.na(map_data$Total.number),], aes(easting, northing),  shape=3)

enter image description here