是否可以使用ggrough(https://xvrdm.github.io/ggroough/index.html)来遮蔽由geom_sf(首选)或可能创建的形状geom_polygon?请参阅此问题以了解先前的问题,该问题给出了我想到的情节的外观以及 Z.Lin 的随附答案,该答案修改了包以使其与当前版本兼容ggplot2:无法复制此 ggplot2 情节。
这是使用创建的地图的 MWE geom_sf,我想使用以下方法对(每个单独的县)进行着色ggrough:
library(tidyverse)
library(magrittr)
library(ggplot2)
library(ggrough)
library(RColorBrewer)
library(tidycensus)
library(viridis)
#install.packages("devtools") # if you have not installed "devtools" package
#devtools::install_github("xvrdm/ggrough")
library(hrbrthemes)
#get nevada shapefile
counties <- get_acs(
geography = "county", year = 2018, geometry = TRUE,
variables = "B19013_001", keep_geo_vars=TRUE
) %>% filter(STATEFP=="32")
counties$GEOID <- as.integer(counties$GEOID)
#############
a <- ggplot() +
geom_sf(data = counties, aes(fill = estimate)) +
scale_fill_viridis(discrete=FALSE, name="", …Run Code Online (Sandbox Code Playgroud) 基于 ggplot2 包,我想为条形图的不同条添加不同的纹理。此外,我想将这些纹理添加到条形图的图例中。
考虑以下可重现的示例:
# Create example data
data_ggp <- data.frame(category = rep(c("cat1", "cat2", "cat3"), 4),
values = c(0.664, 0.045, 0.291, 0.482, 0.029, 0.489, 0.537, 0.027, 0.436, 0.536, 0.028, 0.436),
group = c(rep("group1a", 3), rep("group1b", 3), rep("group2a", 3), rep("group2b", 3)))
# Load ggplot2
library("ggplot2")
# Draw barchart (not overlayed)
ggplot(data_ggp, aes(category, values)) +
geom_bar(stat = "identity", aes(fill = group), position = "dodge") +
scale_fill_manual(" ",
labels = c("group1a", "group1b", "group2a", "group2b"),
values = c("group1a" = "deepskyblue4", "group1b" = "darkolivegreen4",
"group2a" …Run Code Online (Sandbox Code Playgroud) 我只是想知道 ggplot 中是否有可以同时使用彩色和灰度的调色板?
背景是我要投一篇论文,期刊显示在线版本是彩色的,但打印版本却是黑白的。
颜色在我的一些图中非常重要,所以我想知道是否有一些简单的方法可以将大部分信息保留在印刷版本中。
非常感谢。
我有以下代码:
library(ggplot2)
K <- data.frame(KK=c("30", "30", "30", "30","10", "10", "10", "10"),k=c("10", "8", "5", "2","10", "8", "5", "2"),
Precision=c(85.2,87.5,100,100,82.5,83.3,85.2,94.4),
Recall=c(73.3,80,100,100,51.4,54.8,61.1,87.9) ,
Fscore=c(70.8,79.4,100,100,49.1,54.2,62.7,90.3),
Accuracy=c(82.2,86.7,100,100,63.3,66.7,73.3,93.3))
df2 <- reshape2::melt(K, 1:2)
ggplot(df2,
aes(k, value, fill = variable)) +
geom_bar(stat = 'identity', position = 'dodge') +
theme(legend.position = 'top')
Run Code Online (Sandbox Code Playgroud)
但是,我想得到一个这样的图
k的每个值(10,8,5,2)应该是一组条形,条形的每种颜色都是度量。此外,KK值30的小节应为实线,并且KK为10。我不清楚。在我的输出中显示K30的值,但与K10合并并与K30剥离后丢失。
我需要创建一张欧洲地图,以显示各国之间变量的分布情况.我需要黑白地图.我依靠ggplot并遵循这种方法作为例子.我根据这篇博文改变了传奇.所有这一切都适用于此结果:
我的问题是如何改变地图的方式,我错过了填充信息的国家和显示为纯白色的国家有一个纹理覆盖他们(我在想对角线)?
由于我的脚本有点乱,我只是在这里显示ggplot,没有数据准备部分:
require(ggplot2)
plotCoords <- read.csv("http://eborbath.github.io/stackoverflow/PlotCoords.csv")
showCoords <- read.csv("http://eborbath.github.io/stackoverflow/showCoords.csv")
ggplot() +
geom_polygon(
data = plotCoords,
aes(x = long, y = lat, group = group),
fill = "white", colour = "darkgrey", size = 0.6) +
geom_polygon(
data = showCoords,
aes(x = long, y = lat, group = group),
fill = "grey", colour = "black", size = 0.6) +
geom_polygon(
data = showCoords,
aes(x = long, y = lat, group = group, fill = sh_left), …Run Code Online (Sandbox Code Playgroud) 
我正在制作一张世界地图,为不同的变量值用灰色阴影填充国家。对于具有 NA 值的国家/地区,我想用锯齿形、斜线或阴影线填充它们。最终的地图将是黑白的,因此太多的灰色或彩色阴影不会产生可区分的结果。我希望因子变量 (0-3) 的值具有不同的灰色阴影,以及 NA 值的模式。现在,代码为 na.value 显示“蓝色”,但它必须更改。
ggplot(CRSVmap, aes(map_id = region, fill = as.factor(SV)))+
geom_map(map = CRSVmap, color = "black")+
scale_fill_grey(start = 0.99, end = 0.1, na.value = "blue")
Run Code Online (Sandbox Code Playgroud)