- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个点图,但出于某种原因,并不是所有的点都沿着中心对齐。相反,这些点似乎“漂浮”在每个类别的中心网格线上方。我怎样才能调整他们的位置?
当前图代码:
ggplot(data = filter(lastDet,
!ID %in% c("NB2015.341", "NB2018.7",
"NB2018.43", "NB2018.45")),
aes(x = speciesEN, y = yday(depDate))) +
geom_dotplot(aes(fill = factor(year), colour = factor(year)),
binaxis = 'y', stackdir = 'center', dotsize = 0.7,
stackgroups = TRUE,
binpositions = "all",
method = "histodot") +
stat_summary(fun.y = mean, geom = "point",
colour = "black", shape = 4, size = 4) +
scale_y_continuous(limits = c(181, max(yday(lastDet$depDate))),
breaks = c(181, 196, 212, 227, 243),
labels = c("1 Jul", "15 Jul", "1 Aug",
"15 Aug", "1 Sep")) +
scale_colour_manual(values = c("white", "white", "white"),
guide = FALSE) +
scale_fill_manual(values = c("#CA3542", "#FEBC38", "#849FAD")) +
coord_flip() +
labs(y = "Departure date",
x = "",
fill = "Year") +
theme_bw() +
theme(panel.grid.minor = element_blank())
编辑:
重复问题中提供的“hacky”解决方案不适用于我较大的数据框。
编辑 2:
根据要求,这是我的数据框的一个子集。我试图让它尽可能具有代表性。
dput(lastDet.sub)
structure(list(speciesEN = c("Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Bank Swallow", "Bank Swallow", "Bank Swallow",
"Bank Swallow", "Barn Swallow", "Barn Swallow", "Barn Swallow",
"Barn Swallow", "Barn Swallow", "Barn Swallow", "Barn Swallow",
"Barn Swallow", "Barn Swallow", "Barn Swallow", "Barn Swallow",
"Barn Swallow", "Barn Swallow", "Barn Swallow", "Barn Swallow",
"Barn Swallow", "Barn Swallow", "Barn Swallow", "Barn Swallow",
"Barn Swallow", "Cliff Swallow", "Cliff Swallow", "Cliff Swallow",
"Cliff Swallow", "Cliff Swallow", "Cliff Swallow", "Cliff Swallow",
"Cliff Swallow", "Cliff Swallow", "Cliff Swallow", "Tree Swallow",
"Tree Swallow", "Tree Swallow", "Tree Swallow", "Tree Swallow",
"Tree Swallow", "Tree Swallow", "Tree Swallow", "Tree Swallow",
"Tree Swallow"), year = c(2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2014, 2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2014, 2014, 2014, 2014, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015, 2015, 2015, 2015, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018
), depDate = structure(c(1531737145.3837, 1534093849.7991, 1530997725.9412,
1531076069.5422, 1533041446.3001, 1531076076.231, 1533032604.2326,
1534086023.11, 1531737149.7107, 1532882823.5637, 1406899801.4133,
1406297348.1112, 1407276094.4158, 1405278154.7126, 1406330632.0613,
1407490305.4993, 1406370738.3239, 1406655731.0996, 1406552025.8514,
1406366734.892, 1405371083.9787, 1405935159.2899, 1406656817.3111,
1405964739.2527, 1405935269.2718, 1407405240.0903, 1406416984.3628,
1407078925.0925, 1406201767.0139, 1406285074.475, 1407362335.7969,
1405886217.5548, 1406586545.9097, 1406123078.5834, 1439577132.3188,
1439594526.7378, 1438097832.985, 1438097743.3089, 1438470481.0184,
1438246572.18, 1438252727.6824, 1436190169.4567, 1438595642.3985,
1438728341.4292, 1437298553.0341, 1437573409.4331, 1439402462.271,
1437577437.0105, 1438209133.1853, 1438006270.5975, 1438424815.9509,
1438260465.2748, 1439561952.8794, 1441068339.0791, 1437322842.1042,
1438794640.5246, 1439673494.5053, 1439825890.7982, 1438173337.2322,
1438805137.1318, 1438083434.1402, 1436372532.3594, 1435960025.2834,
1439508786.8144, 1439668992.4789, 1439545490.7975, 1438962415.0014,
1437768970.3123, 1438423416.3447, 1438251288.8178, 1439757591.1317,
1437844819.4679, 1438247033.9429, 1439141690.47, 1438207292.6573,
1438171703.2655, 1438277212.7584, 1439199695.1607, 1534507807.6186,
1532702235.5266, 1533820579.7317, 1532957266.8756, 1531824345.5634,
1532598380.2699, 1532098828.52, 1533568517.8915, 1533407138.0839,
1535885104.009, 1533305719.4551, 1535042919.6962, 1533555209.5058,
1535132109.2126, 1534526297.7543, 1535543329.7974, 1535797758.1752,
1535538134.3428, 1535279656.0938, 1532184581.5469, 1534778864.0948,
1534708212.9832, 1534862676.3394, 1535027042.7154, 1534936249.3542,
1535211828.7767, 1534936232.9197, 1535227479.6166, 1534506480.411,
1533161753.2014, 1533115007.6647, 1531570748.0769, 1533673583.6144,
1533201700.8021, 1531239978.3688, 1531843656.4454, 1532604093.761,
1530790685.643, 1531132089.8288, 1530533431.1395, 1530787169.1414,
1530471991.9423, 1530643624.7047, 1530474331.461, 1531679979.9343,
1531673724.9375, 1531579988.1816, 1531394352.5095, 1531831107.0235
), class = c("POSIXct", "POSIXt"), tzone = "UTC")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -127L))
最佳答案
我不经常使用geom_dotplot
,所以不能说我是最熟悉它的。但是根据示例数据,似乎 x 分面并将每个 x 值分配给不同的分面面板可以解决对齐问题。看看这是否适用于您的大型数据框?
# original plot as per question, other than the data portion since lastDet has no ID to filter
p1 <- ggplot(data = lastDet,
aes(x = speciesEN, y = yday(depDate))) +
geom_dotplot(aes(fill = factor(year), colour = factor(year)),
binaxis = 'y', stackdir = 'center', dotsize = 0.7,
stackgroups = TRUE,
binpositions = "all",
method = "histodot") +
stat_summary(fun.y = mean, geom = "point",
colour = "black", shape = 4, size = 4) +
scale_y_continuous(limits = c(181, max(yday(lastDet$depDate))),
breaks = c(181, 196, 212, 227, 243),
labels = c("1 Jul", "15 Jul", "1 Aug",
"15 Aug", "1 Sep")) +
scale_colour_manual(values = c("white", "white", "white"),
guide = FALSE) +
scale_fill_manual(values = c("#CA3542", "#FEBC38", "#849FAD")) +
coord_flip() +
labs(y = "Departure date",
x = "",
fill = "Year") +
theme_bw() +
theme(panel.grid.minor = element_blank())
# alignment fixed by facet
p2 <- p1 +
facet_grid(forcats::fct_rev(speciesEN) ~ ., # use fct_rev to reverse factor levels & match
# x-axis order (can replace with simply
# `speciesEN ~ .`, if this isn't needed)
scales = "free", space = "free") +
theme(strip.background = element_blank(),
strip.text = element_blank(),
panel.spacing = unit(0, "pt"))
默认情况下,每个构面面板都具有相同的大小。相同位置的点数不影响比例限制,因此在 facet_grid
中设置 space = "free"
不会改变分配给每个面的空间量.由于“Bank Swallow”分面面板具有比其他面板更多的具有相同出发日期的点,因此我在 p2 中使用了非常大的高宽比来为每个分面提供足够的空间。
但是,如果我们负担不起这么大的面板尺寸,我们也可以手动计算最大点数:
rel.width <- layer_data(p2) %>%
select(PANEL, y, fill, colour, count) %>%
unique() %>%
group_by(PANEL, y) %>%
summarise(count = sum(count)) %>%
summarise(count = max(count),
y = mean(y, na.rm = TRUE)) %>%
rename(speciesEN = PANEL)
levels(rel.width$speciesEN) <- rev(sort(unique(lastDet$speciesEN)))
> rel.width
# A tibble: 4 x 3
speciesEN count y
<fct> <dbl> <dbl>
1 Tree Swallow 2 192.
2 Cliff Swallow 3 200
3 Barn Swallow 5 229.
4 Bank Swallow 12 210.
并将其作为不可见层添加到图中,以强制每个面调整其空间:
p3 <- p2 +
geom_tile(data = rel.width,
aes(y = y, width = count, height = 1),
alpha = 0)
关于r - geom_dotplot 中未对齐的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406134/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!