I am trying to make a 3D plot on a flat map. I am using the raytracer library and I am folling the wonderful tutorial by Carrie Lo. I wanted to make one modification where the color of the polygon is ignored. Supposedly this is possible per the function documentation.
height_aes - Default
NULL
. Whether thefill
orcolor
aesthetic should be used for height values, which the user can specify by passing eitherfill
orcolor
to this argument. Automatically detected. If bothfill
andcolor
aesthetics are present, thenfill
is default.
So both I and the tutorial have the polygons filled, but I figured I could have the program ignore that part by adding a color outside the AES and set it to black so
# Map map_bg = ggplot(data = state,) + geom_polygon( aes(long,lat,group=group,fill=`Population_CY`), color = 'black') + # Shape scale_fill_gradient(limits=range(state$`Population_CY`), low='skyblue2', high='navy') + layer(geom="path", stat="identity", position="identity", mapping=aes(x=long, y=lat, group=group, color=I('#FFFFFF'))) + theme(legend.position = "none", axis.line=element_blank(), axis.text.x=element_blank(), axis.title.x=element_blank(), axis.text.y=element_blank(), axis.title.y=element_blank(), axis.ticks=element_blank(), panel.background = element_blank()) # Clean Everything # Save as PNG xlim = ggplot_build(map_bg)$layout$panel_scales_x[[1]]$range$range ylim = ggplot_build(map_bg)$layout$panel_scales_y[[1]]$range$range ggsave('map_bg1.png', plot = map_bg, device = NULL, path = NULL, scale = 1, width = diff(xlim)*40, height = diff(ylim)*40, dpi = 300, limitsize = TRUE, units = c("mm")) bg <- png::readPNG("map_bg1.png") # 2D Plot health_insurance = ggplot(raw_data) + annotation_custom(rasterGrob(bg, width=unit(1,"npc"), height=unit(1,"npc")), -Inf, Inf, -Inf, Inf) + xlim(xlim[1],xlim[2]) + # x-axis Mapping ylim(ylim[1],ylim[2]) + # y-axis Mapping geom_point(aes(x=long, y=lat, color=`Direct_Purchase_Only`,size=2)) + scale_colour_gradient(name = 'Health_Insurance\nEmployer', limits=range(raw_data$`Direct_Purchase_Only`), low="skyblue2", high="black") + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.title.x=element_blank(), axis.text.y=element_blank(), axis.title.y=element_blank(), axis.ticks=element_blank(), panel.background = element_blank()) # Clean Everything # 3D Plot plot_gg(health_insurance , multicore = TRUE,height_aes = 'color',offset_edges = TRUE , width = 18,height =8,fov = 70,scale = 300,zoom = 0.5) # Close Windows rgl.close()
this should work but it doesn't and I missing something
https://stackoverflow.com/questions/66827398/raytracers-plot-gg-function-will-not-just-plot-the-contour-map-flat-in-3d-plot March 27, 2021 at 10:07AM
没有评论:
发表评论