【861】Thematic mapping based on R programming
Ref: ggplot2 title : main, axis and legend titles
Ref: ggplot2 标题居中
Ref: ggplot的3种去掉图例的方法 (theme(legend.position="none"))
Ref: R绘图:一文了解ggplot2颜色的设置
Ref: R语言绘图|分级色彩地图
Ref: R语言数据地图——全球填色地图
Ref: R 语言画中国地图
Example: theme(plot.title = element_text(color="red", size=14, face="bold.italic"))
1 2 3 4 5 6 7 8 9 10 11 12 | # Default plot p <- ggplot (ToothGrowth, aes (x=dose, y=len)) + geom_boxplot () + ggtitle ( "Plot of length \n by dose" ) + xlab ( "Dose (mg)" ) + ylab ( "Teeth length" ) p # Change the color, the size and the face of # the main title, x and y axis labels p + theme ( plot.title = element_text (color= "red" , size=14, face= "bold.italic" ), axis.title.x = element_text (color= "blue" , size=14, face= "bold" ), axis.title.y = element_text (color= "#993333" , size=14, face= "bold" ) ) |
Example: theme(plot.title = element_text(hjust = 0.5))
1 2 3 4 5 | library (ggplot2) ggplot (data=mtcars, aes (x=wt, y=mpg)) + geom_point () + labs (title= "Automobile Data" , x= "Weight" , y= "Miles Per Gallon" )+ theme (plot.title = element_text (hjust = 0.5)) #也就加上这一行 |
Example: 使用ggplot2包中的scale_fill_gradient() 函数 填充颜色
1 2 3 | geom_sf (data = countries,color = "black" , aes (fill = gdp_cap_est)) + scale_fill_gradient (low = "white" , high = "red" ) + theme_minimal () |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | library (tidyverse) library (sf) library (openxlsx) library (ggplot2) library (tmap) tmap_mode ( "view" ) library (sfhotspot) library (sfdep) library (dplyr) setwd ( "/Users/libingnan/Documents/09-Samsung/25-New paper-Hotspot-Monkeypox/00_codes/ehsa_data/multi_months_2022_Europe" ) geo_1 <- sf:: read_sf ( "../gdf_europe.gpkg" ) fn = "europe_2021-07-10_2022-06-10" # read in data file_name = substring (fn, 1, 28) df_1 <- readr:: read_csv ( paste0 (file_name, ".csv" ), col_types = "cDd" ) # Create spacetime object called `bos` bos <- spacetime (.data = df_1, .geometry = geo_1, .loc_col = ".region_id" , .time_col = "time_period" ) # conduct EHSA ehsa <- emerging_hotspot_analysis ( x = bos, .var = "value" , k = 1, nsim = 199 ) # should put geo in the first place, otherwise it will triger the projection error geo_ehsa <- merge (geo_1, ehsa, by.x= ".region_id" , by.y= "location" ) # tm_shape: Specify the shape object # tm_polygons: Draw polygons # "clssification" is a column of hotspot_results ggplot () + geom_sf (data = geo_ehsa,color = "black" , aes (fill = classification) ) + scale_fill_manual (values= c ( "new hotspot" = "red" , "new coldspot" = "#F0F0F0" , "consecutive hotspot" = "orange" , "consecutive coldspot" = "#F0F0F0" , "intensifying coldspot" = "#F0F0F0" , "intensifying hotspot" = "purple" , "oscilating hotspot" = "pink" , "oscilating coldspot" = "#F0F0F0" , "persistent coldspot" = "#F0F0F0" , "persistent hotspot" = "pink" , "sporadic coldspot" = "#F0F0F0" , "sporadic hotspot" = "yellow" , "no pattern detected" = "#F0F0F0" )) + theme_minimal () + labs (title = file_name) + theme (plot.title = element_text (hjust = 0.5)) #ggsave(filename=paste0("./images/Rplot_", file_name, ".png")) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2022-07-18 【730】LaTeX添加自定义目录
2014-07-18 【144】重装系统那些事