- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用这些数据...
hogs.sample<-structure(list(Zone = c("B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "D",
"D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D",
"D", "D", "D", "D", "D", "D"), Levelname = c("Medium", "High",
"Low", "Med.High", "Med.High", "Med.High", "Med.High", "Med.High",
"Med.High", "Medium", "Med.High", "Medium", "Med.High", "High",
"Medium", "High", "Low", "Med.High", "Low", "High", "Medium",
"Medium", "Med.High", "Low", "Low", "Med.High", "Low", "Low",
"High", "High", "Med.High", "High", "Med.High", "Med.High", "Medium",
"High", "Low", "Low", "Med.High", "Low"), hogs.fit = c(-0.122,
-0.871, -0.279, -0.446, 0.413, 0.011, 0.157, 0.131, 0.367, -0.23,
0.007, 0.05, 0.04, -0.184, -0.265, -1.071, -0.223, 0.255, -0.635,
-1.103, 0.008, -0.04, 0.831, 0.042, -0.005, -0.022, 0.692, 0.402,
0.615, 0.785, 0.758, 0.738, 0.512, 0.222, -0.424, 0.556, -0.128,
-0.495, 0.591, 0.923)), row.names = c(NA, -40L), groups = structure(list(
Zone = c("B", "D"), .rows = structure(list(1:20, 21:40), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
我正在尝试将基于 Tukeys HSD 的重要字母添加到下面的图中...
library(agricolae)
library(tidyverse)
hogs.plot <- ggplot(hogs.sample, aes(x = Zone, y = exp(hogs.fit),
fill = factor(Levelname, levels = c("High", "Med.High", "Medium", "Low")))) +
stat_summary(fun = mean, geom = "bar", position = position_dodge(0.9), color = "black") +
stat_summary(fun.data = mean_se, geom = "errorbar", position = position_dodge(0.9), width = 0.2) +
labs(x = "", y = "CPUE (+/-1SE)", legend = NULL) +
scale_y_continuous(expand = c(0,0), labels = scales::number_format(accuracy = 0.1)) +
scale_fill_manual(values = c("midnightblue", "dodgerblue4", "steelblue3", 'lightskyblue')) +
scale_x_discrete(breaks=c("B", "D"), labels=c("Econfina", "Steinhatchee"))+
scale_color_hue(l=40, c = 100)+
# coord_cartesian(ylim = c(0, 3.5)) +
labs(title = "Hogs", x = "", legend = NULL) +
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.background = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(),
axis.text.x = element_text(), axis.title.x = element_text(vjust = 0),
axis.title.y = element_text(size = 8))+
theme(legend.title = element_blank(),
legend.position = "none")
hogs.plot
我理想的输出是这样的......
hogs.aov.b <- aov(hogs.fit ~Levelname, data = filter(hogs.sample, Zone == "B"))
hogs.aov.summary.b <- summary(hogs.aov.b)
hogs.tukey.b <- TukeyHSD(hogs.aov.b)
hogs.tukey.b
hogs.aov.d <- aov(hogs.fit ~ Levelname, data = filter(hogs.sample, Zone == "D"))
hogs.aov.summary.d <- summary(hogs.aov.d)
hogs.tukey.d <- TukeyHSD(hogs.aov.d)
hogs.tukey.d
我试过这条路线,但我有很多 pig 以外的物种可以应用它。
library(agricolae)
library(tidyverse)
# get highest point overall
abs_max <- max(bass.dat.d$bass.fit)
# get the highest point for each class
maxs <- bass.dat.d %>%
group_by(Levelname) %>%
# I like to add a little bit to each value so it rests above
# the highest point. Using a percentage of the highest point
# overall makes this code a bit more general
summarise(bass.fit=max(mean(exp(bass.fit))))
# get Tukey HSD results
Tukey_test <- aov(bass.fit ~ Levelname, data=bass.dat.d) %>%
HSD.test("Levelname", group=TRUE) %>%
.$groups %>%
as_tibble(rownames="Levelname") %>%
rename("Letters_Tukey"="groups") %>%
select(-bass.fit) %>%
# and join it to the max values we calculated -- these are
# your new y-coordinates
left_join(maxs, by="Levelname")
类似的例子还有很多
https://www.staringatr.com/3-the-grammar-of-graphics/bar-plots/3_tukeys/但它们都只是手动添加文本。拥有可以采用 Tukey 输出并自动将重要性字母添加到图中的代码会很好。
最佳答案
我不明白你的数据/分析(例如你为什么在 hogs.fit 上使用 exp()
以及字母应该是什么?)所以我不确定这是否正确,但没有其他人在这里回答过是我最好的猜测:
正确示例:
## Source: Rosane Rech
## https://statdoe.com/cld-customisation/#adding-the-letters-indicating-significant-differences
## https://www.youtube.com/watch?v=Uyof3S1gx3M
library(tidyverse)
library(ggthemes)
library(multcompView)
# analysis of variance
anova <- aov(weight ~ feed, data = chickwts)
# Tukey's test
tukey <- TukeyHSD(anova)
# compact letter display
cld <- multcompLetters4(anova, tukey)
# table with factors and 3rd quantile
dt <- group_by(chickwts, feed) %>%
summarise(w=mean(weight), sd = sd(weight)) %>%
arrange(desc(w))
# extracting the compact letter display and adding to the Tk table
cld <- as.data.frame.list(cld$feed)
dt$cld <- cld$Letters
print(dt)
#> # A tibble: 6 × 4
#> feed w sd cld
#> <fct> <dbl> <dbl> <chr>
#> 1 sunflower 329. 48.8 a
#> 2 casein 324. 64.4 a
#> 3 meatmeal 277. 64.9 ab
#> 4 soybean 246. 54.1 b
#> 5 linseed 219. 52.2 bc
#> 6 horsebean 160. 38.6 c
ggplot(dt, aes(feed, w)) +
geom_bar(stat = "identity", aes(fill = w), show.legend = FALSE) +
geom_errorbar(aes(ymin = w-sd, ymax=w+sd), width = 0.2) +
labs(x = "Feed Type", y = "Average Weight Gain (g)") +
geom_text(aes(label = cld, y = w + sd), vjust = -0.5) +
ylim(0,410) +
theme_few()
hogs.sample <- structure(list(Zone = c("B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "D",
"D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D",
"D", "D", "D", "D", "D", "D"), Levelname = c("Medium", "High",
"Low", "Med.High", "Med.High", "Med.High", "Med.High", "Med.High",
"Med.High", "Medium", "Med.High", "Medium", "Med.High", "High",
"Medium", "High", "Low", "Med.High", "Low", "High", "Medium",
"Medium", "Med.High", "Low", "Low", "Med.High", "Low", "Low",
"High", "High", "Med.High", "High", "Med.High", "Med.High", "Medium",
"High", "Low", "Low", "Med.High", "Low"), hogs.fit = c(-0.122,
-0.871, -0.279, -0.446, 0.413, 0.011, 0.157, 0.131, 0.367, -0.23,
0.007, 0.05, 0.04, -0.184, -0.265, -1.071, -0.223, 0.255, -0.635,
-1.103, 0.008, -0.04, 0.831, 0.042, -0.005, -0.022, 0.692, 0.402,
0.615, 0.785, 0.758, 0.738, 0.512, 0.222, -0.424, 0.556, -0.128,
-0.495, 0.591, 0.923)), row.names = c(NA, -40L), groups = structure(list(
Zone = c("B", "D"), .rows = structure(list(1:20, 21:40), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
# anova
anova <- aov(hogs.fit ~ Levelname * Zone, data = hogs.sample)
# Tukey's test
tukey <- TukeyHSD(anova)
# compact letter display
cld <- multcompLetters4(anova, tukey)
# table with factors and 3rd quantile
dt <- hogs.sample %>%
group_by(Zone, Levelname) %>%
summarise(w=mean(exp(hogs.fit)), sd = sd(exp(hogs.fit)) / sqrt(n())) %>%
arrange(desc(w)) %>%
ungroup() %>%
mutate(Levelname = factor(Levelname,
levels = c("High",
"Med.High",
"Medium",
"Low"),
ordered = TRUE))
# extracting the compact letter display and adding to the Tk table
cld2 <- data.frame(letters = cld$`Levelname:Zone`$Letters)
dt$cld <- cld2$letters
print(dt)
#> # A tibble: 8 × 5
#> Zone Levelname w sd cld
#> <chr> <ord> <dbl> <dbl> <chr>
#> 1 D High 1.97 0.104 a
#> 2 D Med.High 1.69 0.206 ab
#> 3 D Low 1.36 0.258 abc
#> 4 B Med.High 1.14 0.0872 abc
#> 5 B Medium 0.875 0.0641 bcd
#> 6 D Medium 0.874 0.111 bcd
#> 7 B Low 0.696 0.0837 cd
#> 8 B High 0.481 0.118 d
ggplot(dt, aes(x = Levelname, y = w)) +
geom_bar(stat = "identity", aes(fill = Levelname), show.legend = FALSE) +
geom_errorbar(aes(ymin = w - sd, ymax = w + sd), width = 0.2) +
labs(x = "Levelname", y = "Average hogs.fit") +
geom_text(aes(label = cld, y = w + sd), vjust = -0.5) +
facet_wrap(~Zone)
关于r - 使用 TukeyHSD 的输出自动向 ggplot 条形图添加重要字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69309101/
我想在我的 android 应用程序中实现一个反馈/评级图表。(就像当你打开 google play 并检查应用程序的反馈时,有一个来自投票它的用户的彩色图表)任何人都可以帮助我如何开始那个?感谢您提
我正在尝试使用 LaTeX 制作条形图。到目前为止我一直不成功,所以任何人都可以帮助我,也许是最近项目的副本?如何使用 pstricks 制作条形图?我会很感激最简单的解决方案,因为我最近才开始使用
我有一个包含 6 个事件及其发生时间跨度的 csv 表。我的变量是开始日期、结束日期和事件 ID。我打算创建一个水平直方图/条形图可视化来显示时间范围,即某些类型的事件持续了多长时间。 X 轴应该有多
我想制作可以指定条形最小值的条形图(很像盒须图中的盒子)。条形图可以做到吗?我怀疑答案在 ggplot 中,但我找不到示例。 这是一些数据: X Jan F
我想使用以下数据来创建可视化: > dput(data) structure(c(1264L, 2190L, 2601L, 1441L, 1129L, 2552L, 1820L, 306L,
我有一个包含正值和负值的数据框。我想显示一个显示两个条形的条形图,一个条形显示正值的百分比,另一个条形图显示负值的百分比。 dummy = pd.DataFrame({'A' : [-4, -3, -
我正在尝试在栏中插入自定义文本,我搜索了很多线程,但仍然没有得到任何解决方案。然后我想减小 y 轴的步长。我已附上我的代码。 jQuery( document ).ready(function() {
我正在使用 pandas 来创建条形图。这是一个例子: df=pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd']) df.
我想在python中制作一个分类图来表示几个变量的范围。我想也许我会使用条形图并为条形设置范围。这是我的条形图 import matplotlib.pyplot as plt import numpy
我有一个显示 3 个条形的堆叠百分比条形图。 JSFiddle:https://jsfiddle.net/Lr0bszj6/ 由于某种原因,条形之间有很多空间并且没有与标签对齐(只有中间一个)。 设置
我正在尝试使用 aChartEngine 将 GPS 数据(正在查看或正在使用的卫星)显示为条形图,但我没有在此 View 中显示任何数据。这是我的代码,所以你能告诉我我犯了什么错误吗? public
我正在使用 this chart implementation . 但是,它分散了我的数据,而不是相互堆叠。 我想在 1970 年堆叠我的第一个数组,在 1975 年堆叠第二个数组。换句话说,我希望有
我正在尝试用不同颜色为条形图中的各个条形着色,比如蓝色表示正,红色表示负。我在互联网上找不到任何有用的东西。我在下面的代码中发现每个条形图都根据第一个条形图的值着色,而不是为每个条形图单独设置颜色:
我刚刚转移到 pandas 0.20/matplotlib 2.0 python 3.6。 (共构成以下版本)。我用 pandas 来绘制条形图,因为 matplotlib 的级别总是太低。着色列的行
我正在尝试制作一个图,其中 x 轴是时间,y 轴是一个条形图,其中的条形图覆盖特定时间段,如下所示: ______________
我有一些非常基本的代码,它可以正常工作,除了所有内容都与顶部对齐...理想情况下,条形图应与底部对齐。我想我可以使用固定定位,因为尺寸是 50px x 50px 的平方,但我更喜欢“固定”少一点的东西
这是我用来 Dim ejex As String, ejey As String Dim graficos As String Worksheets("Sheet1").Activate ejex =
我有一个生成如下条形图的 gnuplot 脚本: 输入数据位于具有多列的文件中,每一列最终都构成图表中的一个集群(示例中显示了 2 个集群)。每个文件都构成图表中的一个条形(示例中有 9 个)。每个文
我正在为我的数据 movies 使用库 ggplot2movies 请记住,我指的是 mpaa 评级和用户评级,这是两个不同的事物。如果您不想加载 ggplot2movies 库,这里是相关数据的示例
有没有一种简单的方法可以使用Pandas DataFrame.plot(kind='bar')方法按列名指定条形颜色? 我有一个脚本,可以从目录中的几个不同数据文件生成多个DataFrame。例如,它
我是一名优秀的程序员,十分优秀!