1

similar to a couple questions, but I have a couple of issues that come up that are unique. (I tried using code from here but it doesn't work for me due to potentially using ggmap instead of ggplot).

I am trying to plot a map with point color changes based on whether plants are infected (1) or not infected (0) with a pathogen. Even better, I would like to change color of points (pathogen status) and shape of points based on plant species (there are 2).

My columns are Sample name, plant species (a or b), lat, lon, pathogen status (0 or 1)

created a map (just an example coordinate used for how i would make the map) map <- get_googlemap(center = c(lon = -111.348284, lat = 38.484637), zoom = 15, maptype = "satellite")

then here's the code. it works as is, but i cannot figure out where to put the conditional statement. I used colors from a national parks pallete.

  ggtitle("Distribution of pathogen") + 
  theme_void() + 
    geom_point(data = data, mapping = aes(x = Longitude, y = Latitude), color = "#7397CB", size=1) +
  theme(
    plot.title = element_text(colour = "#554C6C") , 
    panel.border = element_rect((colour = "#70646E"), fill=NA, size=2)
    ) 

If this has been answered before (which I have checked other questions, but none relate to ggmap, or that x and y values are not what i want to be the reason for color change) please link! Thanks -T

tshates
  • 21
  • 4

1 Answers1

1

Use color as an aesthetic and set to pathogen status, and add shape aesthetic set to species:

 ggtitle("Distribution of pathogen") + 
  theme_void() + 
    geom_point(data = data, mapping = aes(x = Longitude, y = Latitude,
      color=PathogenStatus, shape=Species), size=1) +
  theme(
    plot.title = element_text(colour = "#554C6C") , 
    panel.border = element_rect((colour = "#70646E"), fill=NA, size=2)
    ) 
Djork
  • 3,319
  • 1
  • 16
  • 27
  • Wow! Thanks for your fast response. Here's a follow-up question. Where (how) do I type the code to let it know what shape and what colors to use? – tshates May 05 '20 at 00:44
  • The standard way you would in ggplot ... see `scale_color_manual` and `scale_shape_manual`. – Djork May 05 '20 at 00:46