gpt4 book ai didi

linux - 带有扭曲数据的图

转载 作者:太空宇宙 更新时间:2023-11-04 12:07:54 25 4
gpt4 key购买 nike

问题已被删除,对于给任何推荐的人造成的不便,我们深表歉意

最佳答案

这是一个可能的解决方案,使用了一些虚拟美学。

我对数据的一个子集调用了 geom_boxplot 以排除“Diff”和“rare”。为了得到箱线图的图例,我给了它一个虚拟的颜色美学。

然后我在数据仅为“Diff”或“rare”的子集上调用了 geom_pointggplot 需要长形数据,因此与其过滤值并调用 geom_point 两次,不如调用一次 geom_point 并使用美学来有两种不同的形状。

下一步是控制标签以匹配您所追求的内容并隐藏假人。添加 guide = guide_legend(order = 1)order = 2 设置图例的顺序,以便方法 A 的图例位于方法 B 的图例之前。

一个缺点是方法 B 有两种图例,一种用于颜色,一种用于形状。那是因为他们有两组不同的级别。可以使用 interaction(section, Categories) 代替。

library(tidyverse)
library(data.table)

df <- structure(
list(Categories = c("Aaas", "Aaas", "Aaas", "Aaas", "Bbbs", "Bbbs", "Bbbs", "Bbbs", "Cccs", "Cccs", "Cccs", "Cccs", "Diffs", "Diffs", "Diffs", "Diffs", "rare", "rare", "rare", "rare"),
section = c("red", "blue", "green", "yellow", "red", "blue", "green", "yellow", "red", "blue", "green", "yellow", "red", "blue", "green", "yellow", "red", "blue", "green", "yellow"),
range = c("top1K", "top2K", "top3K", "top4K", "top1K", "top2K", "top3K", "top4K", "top1K", "top2K", "top3K", "top4K", "top1K", "top2K", "top3K", "top4K", "top1K", "top2K", "top3K", "top4K"),
values = c(20L, 32L, 42L, 32L, 21L, 12L, 14L, 14L, 15L, 13L, 43L, 21L, 2L, 10L, 13L, 11L, 3L, 5L, 7L, 9L)),
class = "data.frame",
row.names = c(NA, -20L),
spec = structure(list(cols = structure(list(dummy = structure(list(), class = c("collector_character", "collector")), Categories = structure(list(), class = c("collector_character", "collector")), section = structure(list(), class = c("collector_character", "collector")), range = structure(list(), class = c("collector_character", "collector")), values = structure(list(), class = c("collector_integer", "collector"))),
.Names = c("dummy", "Categories", "section", "range", "values")), default = structure(list(), class = c("collector_guess", "collector"))), .Names = c("cols", "default"), class = "col_spec"), .Names = c("Categories", "section", "range", "values"))


ggplot(df, aes(x = range, y = values)) +
geom_boxplot(aes(fill = "Type A"), data = df[!df$Categories %in% "Diffs" & !df$Categories %like% "rare", ]) +
geom_jitter(data = df[!df$Categories %in% "Diffs" & !df$Categories %like% "rare", ]) +
geom_point(aes(color = Categories, shape = section), data = df[df$Categories %in% "Diffs" | df$Categories %like% "rare", ]) +
scale_fill_manual(values = "white", guide = guide_legend(order = 1)) +
scale_color_discrete(guide = guide_legend(order = 2), labels = c("Type B", "Type C")) +
labs(fill = "Method A", color = "Method B", shape = "Method B")

reprex package 创建于 2018-04-22 (v0.2.0).

关于linux - 带有扭曲数据的图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49968291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com