这是我使用创建的渐变颜色图例rasterImage:
colfunc <- colorRampPalette(c("red", "blue"))
legend_image <- as.raster(matrix(colfunc(20), ncol=1))
plot.new()
rasterImage(legend_image, 0.9, 0, 1, 1)
lbsq <- seq.int(0, 1, l=5)
axis(4, at=lbsq, pos=1, labels=F, col=0, col.ticks=1, tck=-.05)
mtext(lbsq, 4, -.2, at=lbsq, las=2, cex=.6)
Run Code Online (Sandbox Code Playgroud)
我希望在颜色图例周围添加一个细黑色边框。我尝试添加lty = 1,rasterImage但没有成功。我的问题是如何向生成的图像添加黑色边框并调整其颜色和宽度。
我使用软件包安装程序版本0.17.0来更新R和相关的软件包.但是,当我键入时,我收到以下错误消息updater():
Error in strsplit(version_with_dots, "\\.")[[1]] :
subscript out of bounds
Run Code Online (Sandbox Code Playgroud)
我该如何处理这种情况?
我正在使用R在县级绘制美国地图。我从GADM下载了美国的shapefile 。县级形状文件是“ gadm36_USA_2.shp”。然后,我使用下面的代码绘制地图:
library(sf)
library(tidyverse)
us2 <- st_read("<Path>\\gadm36_USA_2.shp")
mainland2 <- ggplot(data = us2) +
geom_sf(aes(fill = NAME_2), size = 0.4, color = "black") +
coord_sf(crs = st_crs(2163),
xlim = c(-2500000, 2500000),
ylim = c(-2300000, 730000)) + guides(fill = F)
Run Code Online (Sandbox Code Playgroud)
如何从“ gadm36_USA_2.shp”中识别出与大湖区相对应的行,以便删除它们?
我了解,除了GADM之外,还有其他获取shapefile的方法。我相信GADM是在全球范围内提供驻地的绝佳来源。我希望借此机会更好地了解从GADM下载的数据。
当然,欢迎使用其他方法来获取美国县级边界数据。我注意到该USAboundaries软件包还提供了国家,州和县级别的公文,但是我在安装关联的USAboundariesData软件包时遇到了困难。除了GADM的shapefile以外,任何以美国方式吸引美国各州的想法都值得欢迎。谢谢。
当我打开 VS Code 时,默认终端是 PowerShell,默认路径是PS E:\Research\GM\Articles\Modularity\Covariance network\Graph theory\Metric basics\Consensus clustering\clustering_programs_5_2.
问题 1:如何将 PowerShell 中的默认路径更改为 C:\Users<用户名>?(下图红线)
问题 2:如何将默认终端从 PowerShell 更改为 cmd?(下图黄色圆圈)

#################################################### ########################## 我遵循了 Geeky 的方法,效果很好。但是,默认路径仍然不是E:\Research\GM\Articles\Modularity\Covariance network\Graph theory\Metric basics\Consensus clustering\clustering_programs_5_2这样的C:\Users<UserName>:

我之前有一篇文章是关于使用GADM中的形状文件绘制美国地图,同时删除五大湖地区的颜色映射。根据@Majid 的建议解决了该问题。
现在,我进一步想要更厚的州边界和更薄的县边界。我首先绘制县级分区统计图,然后添加额外的未填充的州/国家级边界:
library(sf)
library(tidyverse)
library(RColorBrewer) #for some nice color palettes
# US map downloaded from https://gadm.org/download_country_v3.html
# National border
us0 <- st_read("<Path>\\gadm36_USA_0.shp")
# State border
us1 <- st_read("<Path>\\gadm36_USA_1.shp")
# County border
us2 <- st_read("<Path>\\gadm36_USA_2.shp")
# Remove the Great Lakes
# retrieving the name of lakes and excluding them from the sf
all.names = us2$NAME_2
patterns = c("Lake", "lake")
lakes.name <- unique(grep(paste(patterns, collapse="|"),
all.names,
value=TRUE, ignore.case = TRUE))
# Pick the Great Lakes
lakes.name <- lakes.name[c(4, 5, …Run Code Online (Sandbox Code Playgroud)