- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我要绘制三个组的测量值,每个组有五个观察值。我想绘制所有点,但是每个组中的数值都非常接近。改变 alpha 有帮助,但仍然很难观察到单独的点。
因此我想添加一些水平扩展(在 X 轴上)。点的部分重叠是可以的。 geom_jitter() 可以实现这一点,但增加了随机分布,而我想在 X 轴上均匀分布五个点,因为水平轴上的数据没有随机性。
Geom_dotplot() 可以创建均匀分布,但据我所知,它仅适用于离散/合并值。
这是我的 ggplot 输出,以及包含 tribble 格式数据和 ggplot 代码的可重现代码:
library(tidyverse)
df <- tribble(
~projection, ~E.DAP, ~Shielding,
"AP", 2.88755980861244e-06, "None",
"AP", 2.87626262626263e-06, "None",
"AP", 2.87e-06, "None",
"AP", 2.87702265372168e-06, "None",
"AP", 2.87775551102204e-06, "None",
"CRAN", 2.93893129770992e-06, "None",
"CRAN", 2.92857142857143e-06, "None",
"CRAN", 2.93517017828201e-06, "None",
"CRAN", 2.9375e-06, "None",
"CRAN", 2.93831168831169e-06, "None",
"LAO", 6.88053097345133e-06, "None",
"LAO", 6.90217391304348e-06, "None",
"LAO", 6.84489795918367e-06, "None",
"LAO", 6.84792626728111e-06, "None",
"LAO", 6.86425339366516e-06, "None",
"LAO-CRAN", 7.11216730038023e-06, "None",
"LAO-CRAN", 7.1039501039501e-06, "None",
"LAO-CRAN", 7.1042471042471e-06, "None",
"LAO-CRAN", 7.09368635437882e-06, "None",
"LAO-CRAN", 7.10183299389002e-06, "None",
"RAO", 2.48e-06, "None",
"RAO", 2.47540983606557e-06, "None",
"RAO", 2.46979865771812e-06, "None",
"RAO", 2.46206896551724e-06, "None",
"RAO", 2.453125e-06, "None",
"RAO-CRAN", 1.87972508591065e-06, "None",
"RAO-CRAN", 1.87068965517241e-06, "None",
"RAO-CRAN", 1.88461538461538e-06, "None",
"RAO-CRAN", 1.86816720257235e-06, "None",
"RAO-CRAN", 1.8735632183908e-06, "None",
"LAO-CAUD", 6.03324808184143e-06, "None",
"LAO-CAUD", 6.06502242152466e-06, "None",
"LAO-CAUD", 6.04785894206549e-06, "None",
"LAO-CAUD", 6.0402144772118e-06, "None",
"LAO-CAUD", 6.02949061662198e-06, "None",
"RAO-CAUD", 6.30573248407643e-07, "None",
"RAO-CAUD", 6.29834254143646e-07, "None",
"RAO-CAUD", 6.35467980295566e-07, "None",
"RAO-CAUD", 6.38297872340426e-07, "None",
"RAO-CAUD", 6.37755102040816e-07, "None",
"CAUD", 3.81597222222222e-06, "None",
"CAUD", 3.83083511777302e-06, "None",
"CAUD", 3.8330550918197e-06, "None",
"CAUD", 3.82936507936508e-06, "None",
"CAUD", 3.81614349775785e-06, "None",
"AP", 4.53580901856764e-07, "Standard",
"AP", 4.46745562130178e-07, "Standard",
"AP", 4.4973544973545e-07, "Standard",
"AP", 4.44976076555024e-07, "Standard",
"AP", 4.52380952380952e-07, "Standard",
"CRAN", 1.20574162679426e-06, "Standard",
"CRAN", 1.20113314447592e-06, "Standard",
"CRAN", 1.19130434782609e-06, "Standard",
"CRAN", 1.19349593495935e-06, "Standard",
"CRAN", 1.19757575757576e-06, "Standard",
"LAO", 1.50961538461538e-06, "Standard",
"LAO", 1.50761421319797e-06, "Standard",
"LAO", 1.51209677419355e-06, "Standard",
"LAO", 1.52216748768473e-06, "Standard",
"LAO", 1.51476793248945e-06, "Standard",
"LAO-CRAN", 2.96213425129088e-06, "Standard",
"LAO-CRAN", 2.95991561181435e-06, "Standard",
"LAO-CRAN", 2.95e-06, "Standard",
"LAO-CRAN", 2.95744680851064e-06, "Standard",
"LAO-CRAN", 2.95266272189349e-06, "Standard",
"RAO", 1.51515151515152e-07, "Standard",
"RAO", 1.52173913043478e-07, "Standard",
"RAO", 1.52866242038217e-07, "Standard",
"RAO", 1.57575757575758e-07, "Standard",
"RAO", 1.59420289855072e-07, "Standard",
"RAO-CRAN", 2.41379310344828e-07, "Standard",
"RAO-CRAN", 2.33050847457627e-07, "Standard",
"RAO-CRAN", 2.34741784037559e-07, "Standard",
"RAO-CRAN", 2.33812949640288e-07, "Standard",
"RAO-CRAN", 2.34817813765182e-07, "Standard",
"LAO-CAUD", 1.89125295508274e-07, "Standard",
"LAO-CAUD", 1.87110187110187e-07, "Standard",
"LAO-CAUD", 1.89309576837416e-07, "Standard",
"LAO-CAUD", 1.90821256038647e-07, "Standard",
"LAO-CAUD", 1.89189189189189e-07, "Standard",
"AP", 3.7542662116041e-08, "XRB",
"AP", 3.89972144846797e-08, "XRB",
"AP", 4.15335463258786e-08, "XRB",
"AP", 3.83275261324042e-08, "XRB",
"AP", 4.09556313993174e-08, "XRB",
"CRAN", 4e-08, "XRB",
"CRAN", 4.08163265306122e-08, "XRB",
"CRAN", 4.06905055487053e-08, "XRB",
"CRAN", 3.94574599260173e-08, "XRB",
"CRAN", 3.90835579514825e-08, "XRB",
"LAO", 6.47249190938511e-08, "XRB",
"LAO", 6.69144981412639e-08, "XRB",
"LAO", 6.42570281124498e-08, "XRB",
"LAO", 6.19834710743802e-08, "XRB",
"LAO", 6.25e-08, "XRB",
"LAO-CRAN", 5.31914893617021e-08, "XRB",
"LAO-CRAN", 5.11247443762781e-08, "XRB",
"LAO-CRAN", 5.30821917808219e-08, "XRB",
"LAO-CRAN", 5.17857142857143e-08, "XRB",
"LAO-CRAN", 5.31732418524871e-08, "XRB",
"RAO", 3.30578512396694e-08, "XRB",
"RAO", 3.38983050847458e-08, "XRB",
"RAO", 3.33333333333333e-08, "XRB",
"RAO", 3.07017543859649e-08, "XRB",
"RAO", 3.2171581769437e-08, "XRB",
"RAO-CRAN", 3.44827586206897e-08, "XRB",
"RAO-CRAN", 3.5264483627204e-08, "XRB",
"RAO-CRAN", 3.25581395348837e-08, "XRB",
"RAO-CRAN", 3.43007915567282e-08, "XRB",
"RAO-CRAN", 3.37837837837838e-08, "XRB",
"LAO-CAUD", 5.70776255707763e-08, "XRB",
"LAO-CAUD", 5.50847457627119e-08, "XRB",
"LAO-CAUD", 5.51876379690949e-08, "XRB",
"LAO-CAUD", 5.42797494780793e-08, "XRB",
"LAO-CAUD", 5.53191489361702e-08, "XRB",
"RAO-CAUD", 2.1505376344086e-08, "XRB",
"RAO-CAUD", 1.52990264255911e-08, "XRB",
"RAO-CAUD", 1.58033362598771e-08, "XRB",
"RAO-CAUD", 1.47679324894515e-08, "XRB",
"RAO-CAUD", 1.60213618157543e-08, "XRB",
"CAUD", 3.84024577572965e-08, "XRB",
"CAUD", 3.98671096345515e-08, "XRB",
"CAUD", 4e-08, "XRB",
"CAUD", 3.92156862745098e-08, "XRB",
"CAUD", 3.94574599260173e-08, "XRB",
"RAO-CAUD", 4.52961672473868e-08, "Standard",
"RAO-CAUD", 4.12844036697248e-08, "Standard",
"RAO-CAUD", 4.83870967741936e-08, "Standard",
"RAO-CAUD", 4.29184549356223e-08, "Standard",
"RAO-CAUD", 4.38356164383562e-08, "Standard",
"CAUD", 8.58974358974359e-08, "Standard",
"CAUD", 8.70646766169154e-08, "Standard",
"CAUD", 8.66372980910426e-08, "Standard",
"CAUD", 8.67579908675799e-08, "Standard",
"CAUD", 8.70113493064313e-08, "Standard",
"LAO90", 3.38266384778013e-08, "XRB",
"LAO90", 3.34346504559271e-08, "XRB",
"LAO90", 3.2258064516129e-08, "XRB",
"LAO90", 3.21543408360129e-08, "XRB",
"LAO90", 3.20987654320988e-08, "XRB",
"LAO90", 8.60215053763441e-08, "Standard",
"LAO90", 8.88888888888889e-08, "Standard",
"LAO90", 8.44686648501362e-08, "Standard",
"LAO90", 8.90804597701149e-08, "Standard",
"LAO90", 8.67052023121387e-08, "Standard",
"LAO90", 1.96982378854626e-05, "None",
"LAO90", 1.97443820224719e-05, "None",
"LAO90", 1.96883720930233e-05, "None",
"LAO90", 1.96856540084388e-05, "None",
"LAO90", 1.96415770609319e-05, "None"
)
ggplot(df , aes(x=projection, y=E.DAP, color=Shielding)) +
geom_jitter(size = 2.5, width=0.2, height=0, alpha =0.8) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1, size=8)) +
labs(title= "mSv/DAP according to projection",
y="mSv/mGy*cm2 ", x="")+
theme(legend.position = c(0.85, 0.8), legend.key = element_rect(colour = "transparent", fill = "transparent")) +
scale_color_manual(values=c(c("#69ac5c", "#5b86c3","#c7533b"))) +
theme(legend.title = element_blank())
最佳答案
包 ggbeeswarm
可以使用...可以使用不同的形状或 geom_beeswarm
的参数来增强外观:alpha
、dodge.width
或 groupOnX
.
设置dodge.width
强制点按Shielding
变量分组。更新后的答案名义上包括 0.1 的值,将 dodge.width 设置为更接近于零使得看起来好像没有躲闪并将来自相同屏蔽值的点保持在一起。较大的 dodge.width 值将有助于区分 x 变量的点,例如“CAUD”。
为确保 Shielding
的重叠绘制是一致的,请创建绘图顺序变量。通过 Shielding 排列数据任意设置,以便最后一个变量绘制在最后,这可以更改以适应。
library(ggplot2)
library(dplyr)
library(ggbeeswarm)
df1 <-
df %>%
arrange(Shielding) %>%
mutate(plot_order = row_number())
ggplot(df1, aes(x = projection, y = E.DAP, color = Shielding, order = plot_order)) +
geom_beeswarm(size = 2.5, alpha = 0.9, dodge.width = 0.1) +
scale_color_manual(values=c(c("#69ac5c", "#5b86c3","#c7533b"))) +
labs(title= "mSv/DAP according to projection",
y="mSv/mGy*cm2 ", x="")+
theme(legend.title = element_blank(),
legend.position = c(0.85, 0.8),
legend.key = element_rect(colour = "transparent", fill = "transparent"),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1, size=8))
由 reprex package 创建于 2021-12-21 (v2.0.1)
关于r - 在 ggplot2 中添加完全相同数量的水平传播/"jitter"/闪避,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70434268/
前 R 用户,我曾经通过 ggplotly() 函数广泛地结合 ggplot 和 plot_ly 库来显示数据。 刚到 Python 时,我看到 ggplot 库可用,但在与 plotly 的简单组合
ggplotly 使用 ggplot 删除 geom_line 图的图例。 见例如以下: library(plotly) g % ggplotly() 关于r - ggplotly 从 gg
我有一个 ggplot我试图以非常简约的外观制作线图的问题。我已经摆脱了图例,转而使用每行右侧的文本标签。如果标签不是那么长,它可能不会那么明显,但如果网格线停在最大 x 值(在这种情况下,在 201
我想使用相同的 ggplot 代码以我的数据框中的数字为条件生成 8 个不同的数字。通常我会使用 facet_grid,但在这种情况下,我希望最终得到每个单独数字的 pdf。例如,我想要这里的每一行一
当我在 ggplot 上使用 geom_text 时,与 ggplot 的“填充”选项发生冲突。 这是问题的一个明显例子: library(ggplot2) a=ChickWeight str(a)
是否可以结合使用 ggplot ly 和拼凑而成的ggplot? 例子 这将并排显示两个图 library(ggplot2) library(plotly) library(patchwork) a
我想绘制一个图表,其中 y 轴以百分比表示: p = ggplot(test, aes(x=creation_date, y=value, color=type)) + geom_line(aes
如何去除ggsave中的白边距? 我的问题和Remove white space (i.e., margins) ggplot2 in R一模一样。然而,那里的答案对我来说并不理想。我不想对固定但未知
我有一个带有一些文本层的条形图,在 ggplot 库中一切正常,但现在我想添加一些与 ggplotly 的交互性,但它无法显示文本层 我更新了所有软件包但问题仍然存在 df = read.table(
当我尝试在 ggplot 中为我的箱线图设置自定义宽度时,它工作正常: p=ggplot(iris, aes(x = Species,y=Sepal.Length )) + geom_boxplot(
我正在尝试为 ggplot 密度创建一个图例,将一个组与所有组进行比较。使用此示例 - R: Custom Legend for Multiple Layer ggplot - 我可以使用下面的代码成
所以我试图在一个多面的 ggplot 上编辑 y 值,因为我在编织时在情节上有几个不准确之处。我对 R 和 R Markdown 很陌生,所以我不太明白为什么,例如,美国的 GDP PPP 在美元金额
我需要在 python 条形图的 x 轴 ggplot 上格式化日期。 我该怎么做? 最佳答案 使用 scale_x_date() 格式化 x 轴上的日期。 p = ggplot(aes(x='dat
我想使用 ggplotly因为它的副作用相同ggplot甚至graphics做。我的意思是当我 knitr::knit或 rmarkdown::render我期望的 Rmd 文档 print(obj)
我在下面有一个简单的应用程序,它显示了一个 ggplot。 ggplot 在控制台中生成警告(见底部图片)。我想捕获警告,并将其显示在应用程序的情节下方。 这是我的代码: library(shiny)
如果显示的基本数据集很大(下面的示例工作代码),则在 Shiny 的应用程序中向/从 ggplot 添加/删除图层可能需要一段时间。 问题是: 有没有办法缓存 ggplot(基本图)并添加/删除/修改
我正在组合 ggplot 的多个绘图,使用网格视口(viewport),这是必要的(我相信),因为我想旋转绘图,这在标准 ggplot 中是不可能的,甚至可能是 gridExtra 包。 我想在两个图
我可以使用 lattice 在 R 中绘制相对频率直方图包裹: a <- runif(100) library(lattice) histogram(a) 我想在 ggplot 中获得相同的图形.我试
我需要重新安装 R,但我现在遇到了 ggplot 的一个小问题。我确信有一个简单的解决方案,我感谢所有提示! 我经常使用堆叠面积图,通常我通过定义因子水平并以相反的顺序绘制来获得所需的堆叠和图例顺序。
新的并且坚持使用ggplot: 我有以下数据: tribe rho preference_watermass 1 Luna2 -1.000 hypolimnic 2 OP10I-A1
我是一名优秀的程序员,十分优秀!