- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想先绘制一堆区域,然后用相同的单个 alpha 值显示生成的整体区域。所以不要这样:
library(tidyverse)
dat <- tribble(
~xmin, ~xmax, ~ymin, ~ymax,
10, 30, 10, 30,
20, 40, 20, 40,
15, 35, 15, 25,
10, 15, 35, 40
)
ggplot() +
geom_rect(data = dat,
aes(
xmin = xmin,
xmax = xmax,
ymin = ymin,
ymax = ymax
),
alpha = 0.5)
我希望将其作为我的结果:
由 reprex package 于 2022-07-26 创建(v2.0.1)
我觉得我的问题的答案可能与 this thread 中的答案相似但我并不完全理解它,因此不确定。另请注意,我使用 geom_rect()
作为代表,但最终我希望它适用于 ggforce::geom_circle()
.
Quinten's first answer ,它指向 scale_alpha(range = ..., limits = ...)
,不幸的是没有回答我的问题,因为它显然只能导致不透明的区域。
Quinten's updated answer是我可以接受上述代表的一种解决方法。但是,正如我上面提到的,我希望它适用于 ggforce::geom_circle()
.不幸的是,我想我现在必须更具体并创建另一个代表。 (对不起)
library(ggforce)
#> Lade nötiges Paket: ggplot2
dat <- data.frame(
x = c(1, 1.3, 1.6),
y = c(1, 1, 1),
circle = c("yes", "yes", "no")
)
ggplot() +
coord_equal() +
theme_classic() +
geom_circle(
data = subset(dat, circle == "yes"),
aes(x0 = x, y0 = y, r = 0.5, alpha = circle),
fill = "grey",
color = NA,
show.legend = TRUE
) +
geom_point(
data = dat,
aes(x, y, color = circle)
) +
scale_color_manual(
values = c("yes" = "blue", "no" = "red")
) +
scale_alpha_manual(
values = c("yes" = 0.25, "no" = 0)
)
由 reprex package 于 2022-08-17 创建(v2.0.1)
最佳答案
ggblend
不久前我还看到了 ggblend
,但不确定它是否能解决您的问题,幸运的是它可以解决!你可以做两件事:
代码:
#remotes::install_github("mjskay/ggblend")
library(ggblend)
library(ggforce)
# reprex 1 ----------------------------------------------------------------
library(tidyverse)
dat <- tribble(
~xmin, ~xmax, ~ymin, ~ymax,
10, 30, 10, 30,
20, 40, 20, 40,
15, 35, 15, 25,
10, 15, 35, 40
)
p1 <- ggplot() +
geom_rect(data = dat,
aes(
xmin = xmin,
xmax = xmax,
ymin = ymin,
ymax = ymax
),
alpha = 0.3) %>% blend("source")
p1
# reprex 2 ----------------------------------------------------------------
dat <- data.frame(
x = c(1, 1.3, 1.6),
y = c(1, 1, 1),
circle = c("yes", "yes", "no")
)
p2 <- ggplot() +
coord_equal() +
theme_classic() +
geom_circle(
data = subset(dat, circle == "yes"),
aes(x0 = x, y0 = y, r = 0.5, alpha = circle),
fill = "grey",
color = NA,
show.legend = TRUE
) %>% blend("source") +
geom_point(
data = dat,
aes(x, y, color = circle)
) +
scale_color_manual(
values = c("yes" = "blue", "no" = "red")
) +
scale_alpha_manual(
values = c("yes" = 0.25, "no" = 0)
)
p2
#ggsave(plot = p2, "p2.pdf", device = cairo_pdf)
type = "cairo"
将对象保存为 png
,如下所示:library(ggblend)
library(ggforce)
# reprex 1 ----------------------------------------------------------------
library(tidyverse)
dat <- tribble(
~xmin, ~xmax, ~ymin, ~ymax,
10, 30, 10, 30,
20, 40, 20, 40,
15, 35, 15, 25,
10, 15, 35, 40
)
p1 <- ggplot() +
geom_rect(data = dat,
aes(
xmin = xmin,
xmax = xmax,
ymin = ymin,
ymax = ymax
),
alpha = 0.3) %>% blend("source")
#> Warning: Your graphics device, "quartz_off_screen", reports that blend = "source" is not supported.
#> - If the blending output IS NOT as expected (e.g. geoms are not being
#> drawn), then you must switch to a graphics device that supports
#> blending, like png(type = "cairo"), svg(), or cairo_pdf().
#> - If the blending output IS as expected despite this warning, this is
#> likely a bug *in the graphics device*. Unfortunately, several
#> graphics do not correctly report their capabilities. You may wish to
#> a report a bug to the authors of the graphics device. In the mean
#> time, you can disable this warning via options(ggblend.check_blend =
#> FALSE).
#> - For more information, see the Supported Devices section of
#> help('blend').
png(filename = "plot1.png", type = "cairo")
# Output in your own folder:
p1
dev.off()
#ggsave(plot = p1, "p1.pdf", device = cairo_pdf)
# reprex 2 ----------------------------------------------------------------
dat <- data.frame(
x = c(1, 1.3, 1.6),
y = c(1, 1, 1),
circle = c("yes", "yes", "no")
)
p2 <- ggplot() +
coord_equal() +
theme_classic() +
geom_circle(
data = subset(dat, circle == "yes"),
aes(x0 = x, y0 = y, r = 0.5, alpha = circle),
fill = "grey",
color = NA,
show.legend = TRUE
) %>% blend("source") +
geom_point(
data = dat,
aes(x, y, color = circle)
) +
scale_color_manual(
values = c("yes" = "blue", "no" = "red")
) +
scale_alpha_manual(
values = c("yes" = 0.25, "no" = 0)
)
#> Warning: Your graphics device, "quartz_off_screen", reports that blend = "source" is not supported.
#> - If the blending output IS NOT as expected (e.g. geoms are not being
#> drawn), then you must switch to a graphics device that supports
#> blending, like png(type = "cairo"), svg(), or cairo_pdf().
#> - If the blending output IS as expected despite this warning, this is
#> likely a bug *in the graphics device*. Unfortunately, several
#> graphics do not correctly report their capabilities. You may wish to
#> a report a bug to the authors of the graphics device. In the mean
#> time, you can disable this warning via options(ggblend.check_blend =
#> FALSE).
#> - For more information, see the Supported Devices section of
#> help('blend').
png(filename = "plot2.png", type = "cairo")
# Output in your folder
p2
dev.off()
#ggsave(plot = p2, "p2.pdf", device = cairo_pdf)
创建于 2022-08-17,使用 reprex v2.0.2
更新
您可以做的是使用 sf
包中的 st_union
对区域进行 UNION,这样您就可以得到一个区域,而不是像这样的重叠区域:
library(tidyverse)
library(sf)
dat <- tribble(
~xmin, ~xmax, ~ymin, ~ymax,
10, 30, 10, 30,
20, 40, 20, 40,
15, 35, 15, 25,
10, 15, 35, 40
)
area1 <- dat %>%
slice(1) %>%
as_vector() %>%
st_bbox() %>%
st_as_sfc()
area2 <- dat %>%
slice(2) %>%
as_vector() %>%
st_bbox() %>%
st_as_sfc()
area3 <- dat %>%
slice(3) %>%
as_vector() %>%
st_bbox() %>%
st_as_sfc()
area4 <- dat %>%
slice(4) %>%
as_vector() %>%
st_bbox() %>%
st_as_sfc()
all_areas <- st_union(area1, area2) %>%
st_union(area3) %>%
st_union(area4)
ggplot(all_areas) +
geom_sf(alpha = 0.5, fill = "grey", colour = "grey") +
theme(legend.position = "none")
ggplot(all_areas) +
geom_sf(alpha = 0.8, fill = "grey", colour = "grey") +
theme(legend.position = "none")
由 reprex package 于 2022-08-17 创建(v2.0.1)
第一个答案
也许你想要这个,你可以使用 scale_alpha
和 range
和 limits
来保持相同的区域 alpha
像这样:
library(tidyverse)
dat <- tribble(
~xmin, ~xmax, ~ymin, ~ymax,
10, 30, 10, 30,
20, 40, 20, 40,
15, 35, 15, 25,
10, 15, 35, 40
)
ggplot() +
geom_rect(data = dat,
aes(
xmin = xmin,
xmax = xmax,
ymin = ymin,
ymax = ymax,
alpha = 0.5
)) +
scale_alpha(range = c(0, 1), limits = c(0, 0.5)) +
theme(legend.position = "none")
由 reprex package 于 2022-07-26 创建(v2.0.1)
关于r - 即使对于 ggplot2 中的重叠区域,相同/修复 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73119065/
我对具有 2 个轴的数据有交叉识别问题,例如 A = array([['x0', 'y0', 'data0', 'data0'], ['x0', 'y0', 'data0', '
我知道这是代码有点傻,但有人可以解释为什么 isList [42]返回 True而isList2 [42]打印 False ,以及如何防止这种情况?我想更好地理解一些更晦涩的 GHC 类型扩展,我认为
我正在使用memmove(),但目标似乎正在覆盖源,或者也许我不明白覆盖是什么。我有一个 char 数组(目标),然后是一个指向目标的指针,该指针位于 vector 内部。 char destinat
以下AS3代码有时会导致音频多次播放,就像疯狂的回声一样,几乎同时播放。通常使用该URL都可以,但是当我使用https://soundcloud.com url时,它总是会发疯。在极少数情况下,我认为
我正在尝试在 android 2.2 中实现类似操作栏的东西。这是我的 main.xml
如何避免第一个值的重叠问题 而且,我怎样才能看到最后一个被剪裁的值? 最佳答案 我认为您在修改轴上的样式和调整视口(viewport)之间有几种选择。 我会尝试: 禁用左轴,启用右轴 chart.le
我正在构建一个简单的应用程序,您可以在其中使用纸娃娃之类的工具来描述您的外观。 Check out this image.计划是有 4 个水平 ScrollView :第一个用于发型,第二个用于面部毛
我有一个问题...我在绝对布局中有两个 ScrollView 。换句话说,它们是全屏的并且相互重叠 上面的scrollview是水平滚动的,下面的是垂直滚动的scrollview。 当我水平滚动时,我
我看了一些类似的问题,但我不太明白在我的层次结构中我应该做什么? 我有 用于屏幕底部的标签菜单 和 对于其他将创建的 fragment 。 我有 9 个标签菜单,每个都是 fragment 。 一
在我的 Android 应用程序中,我有一个编辑文本和一个按钮,单击该按钮会向我的主要 Activity 添加一个 fragment ,其中包含在我的编辑文本中写入的消息。问题是,当我更改消息并单击按
在我的分段控件中,有时标题比其段宽。我怎样才能让它截断? 假设第 1 段的标题是 Text overlaps,第 2 段的名称是 ok。 我希望它看起来如何: [Text ov...| ok
我想创建一个带有重叠单元格的 uitableview,如下图所示。问题是,即使我为单元格的内容 View 设置 clipsToBounds = NO,单元格假标题(例如,将与前一个单元格重叠的西类牙语
有了这个CSS .addProblemClass{ width:300px; height:300px; /*width:25%; height:40%;*/
我有跨窗口移动的图像(2 行),当我离开页面选项卡时,然后返回它,所有图像都相互堆叠。 JS代码(记入jfriend00) function startMoving(img) { va
这是我的一段代码。图像在 23 毫秒后正常可见,但永远不会像第二行所示那样返回隐藏状态。如果我将其从 17 毫秒更改为大于 23 毫秒的值,它就会起作用。反之亦然,如果我将第一行更改为 16 毫秒,它
我正在可汗学院为学校项目编写一款太空入侵者游戏,但我不知道如何在子弹和外星人之间进行碰撞,然后摆脱子弹所碰撞的外星人。这是非常基本的 JS,尽管我尝试过,但我不太明白如何将有关该主题的其他答案放入我的
当我尝试重新加载 tableView 的数据时出现奇怪的重叠,导致单元格的高度发生变化(使用 UITableViewAutomaticDimension),然后内容与上面的单元格重叠,无法弄清楚怎么做
我是一个新手,如果这是一个愚蠢的问题,请原谅我。我想有一个部分与标题分开,但发生了两种情况: (1) 当我把 在 下面,它们相互重叠,如下所示: Section overlapping header
我正在尝试创建两个 那是重叠的。唯一的问题是第二个 在第一个的前面它必须是相反的。我尝试设置第一个 的 z-index至 1但它仍然不起作用。 这是我的代码: #content{ backgrou
是否有重叠 2 个 div 的有效方法。 我有以下内容,但无法让它们重叠。 #top-border{width:100%; height:60px; background:url(image.jpg)
我是一名优秀的程序员,十分优秀!