ggplot2 - R raster plot non-continuous color scale -


OK, so I'm getting an epic brain on it, so any help would be appreciated. I am plotting the data using raster and ggplot. Below I am an example to produce that figure:

  r = raster (ncol = 18, nrow = 18, xmn = -120, xmx = -80, ymn = 10, ymx = 45) outline = as.data.frame (map ("world", xlim = c (-120, -80), ylim = c (10, 45), Plot = wrong) [c ("x", "y")] = map (geo_path (aes (x, y), inherit.aes = FALSE, data = outline, alpha = 0.8, show_guide = FALSE, color = " Gray ") lat = runif (10, 10,45) lon = Ranif (10, -120, -80) data = ranif (10, -3,2) xy = cbind (x = lan, y = lat) dummy = Rasterize (xi, r, field = data, fun = Cited) dummy .df = as.data.frame (dummy, row.Name = NULL, alternative = true, xy = TRUE, centroids = TRUE) colnames (dummy.df) & lt; -c ("lon", "lat "Data") Ggplot (data = dummy.df, AES (x = lawn, y = axis)) + gOm_tile (AES (fill = data)) + scale_colour_brewer (palette = "set1")  < / Pre> 

What is the problem with me, it's the continuous color scale that uses it I have seen everywhere, but nothing can be found for my issue (or at least I spent seeing it 6) Could not get in hours). What do I want to have a color scale, using the example given above, between the values ​​of 3 and -2.5, the value of the data will be yellow, between -2.5 and -2.0, orange, -2.0 and -1.5 and yellow Kind . I'm not dead on using scale_colour_brewer, so any suggestions will be appreciated and I will be excluded from my misery. Thanks!

There were some errors, I did not know which package function was map So I do not understand what this answer is for you.

  Library (GG Plot 2) Library (Raster) Library (Arcolterbrower) R = Raster (nucleus = 18, enro = 18, xmn = -120, xmx = -80, ymn = 10, ymx = 45) Profile = as.data.frame (Map ("World", xlim = c (-120, -80), ylim = c (10, 45), Plot = FALSE) [c ("x", "y ")] Map = geom_path (aes (x, y), inherit.aes = FALSE, data = outline, alpha = 0.8, show_guide = FALSE, color =" gray ") Lat = runif (10, 10,45) lon = Runif (10, -120, -80) data = ranif (10, -3,2) xy = cbind (x = lan, y = lat) dummy = rastise (xy, r, field = data, fun = mean) Dummy.df = as.data.frame (dummy, row.Name = NULL, alternative = TRUE, xy = TRUE, centroids = TRUE) colnames (dummy.df) & lt; - c ("lon", "lat", "data") breaks 2 & lt; -seq (-2.5,2,0.5) dummy D $$ Colonel & lt; -s.character (cut (dummy.df $ data, break = breaks2)) dummy.df $ Col [is.na (dummy.df $ Col)] & ​​lt; - "Empty" # This palette does not have enouth color, so I added green color & lt; -c (brewer.pal (9, "set 1"), "green") name (color) & lt; - Unique (dummy.df $ Col) color + "Grey40" ggplot (data = dummy.df, aes (x = lon, y = lat)) + geom_tile (aes (fill = col)) + scale_fill_manual (values ​​= C (colors))  

You can choose the color manually

You can choose the color manually, but you must give them the proper name


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -