我正在尝试使用 ggplot2 绘制箱线图。样本数据是这样的。
> sampe
count genotype
71 mt
50 mt
71 mt
95 wt
60 mt
63 mt
75 mt
82 wt
93 wt
87 wt
61 mt
102 wt
60 mt
78 wt
78 wt
87 wt
84 wt
104 wt
81 wt
85 mt
> qplot(factor(genotype),count,data=sampe,geom="boxplot")
Run Code Online (Sandbox Code Playgroud)
上面的命令产生这样的情节:

这里怎么了??为什么会这样??即使是下面的代码也会产生相同的输出。
ggplot(sampe,aes(x=factor(genotype),y=count))+geom_boxplot()
Run Code Online (Sandbox Code Playgroud) 我想制作一个箱线图,显示执行行为(警报)所花费的时间如何受到两个变量(时段=上午/下午和访客级别=高/低)的影响。
Alert ~ Period + Vis.Level
Run Code Online (Sandbox Code Playgroud)
“警报”是一组 12 个数字,显示与其他两个作为重要分类变量的清醒时间。我看过其他例子,但似乎没有一个适合此类问题。
我知道我正在寻找的图表上会有 4 个箱线图...据说是
在 x 轴上。
任何帮助都会很棒!
Alert Vis.Level Period
1 0.0 Low Morning
2 1.0 Low Morning
3 0.0 Low Morning
4 11.5 Low Afternoon
5 6.0 Low Afternoon
6 11.5 Low Afternoon
7 0.0 High Morning
8 0.0 High Morning
9 0.0 High Morning
10 0.0 High Afternoon
11 2.5 High Afternoon
12 7.5 High Afternoon
Run Code Online (Sandbox Code Playgroud) 我做了一个箱形图,比较了男子游泳奥运会运动员的年龄,然后他们是否获得了奖牌.我想知道如何编写代码来获得没有奖牌的盒子图的五个数字摘要和带奖牌的盒子图(我将奖章改为一个因子).我试过了summary(age,medal.f),summary(age~medal.f)似乎没有任何工作/我不知道如何分离箱形图.有关如何做到这一点的任何想法?
我想知道是否有直接的方法将箱线图的填充分配为他们的IQR值?
library(ggplot2)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot(aes(fill = ??)) # IQR values?
Run Code Online (Sandbox Code Playgroud) 我想创建一个箱线图,ggplot2并且我想按照数据框的顺序组织图,例如
我知道 R 按字母顺序组织箱线图。我怎么能够:
- 按味道 - 颜色 - 容量的顺序组织 X 轴
- 交换盒子,即先是绿色,然后是橙色,而不是橙色和绿色
- 也切换图例顺序,首先是 NaCl,然后是 O_{2}
library(ggplot2)
library(readxl)
Chemical <- rep(c("NaCl", "Al2"), times = 3, each = 4)
Quality <- rep(c("Taste", "Color of package", "Capacity"), times = 1, each = 8)
Accepted <- seq(0, 100, by = 100/23)
DF <- data.frame(Chemical, Quality, Accepted)
ggplot(DF, aes(x = Quality, y = Accepted, fill = Chemical)) +
geom_boxplot() +
scale_fill_manual(values = c("orange", "green"),
labels = expression("Al"[2], "NaCl")) +
xlab("") +
theme(legend.position = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在类似于此的箱线图中评估上述数据:https://www.r-graph-gallery.com/89-box-and-scatter-plot-with-ggplot2.html

我希望 x 轴反映我的“年份”变量,并且每个箱线图将 8 种方法评估为分布。最终我想确定与该分布相关的“选定”变量,但目前我只想渲染这个东西!
我弄清楚如何编码我的 y 变量,但无论我尝试什么,我都会遇到各种错误。我认为 PY 需要是 as.factor 但我已经尝试过一些这样的代码,但我只是得到了其他错误。
无论如何,这是我的代码(发送帮助):
# Libraries
library(tidyverse)
library(hrbrthemes)
library(viridis)
library(ggplot2)
library(readxl) # For reading in Excel files
library(lubridate) # For handling dates
library(dplyr) # for mutate and pipe functions
# Path to current and prior data folders
DataPath_Current <- "C:/R Projects/Box Plot Test"
Ult_sum <- read_excel(path = paste0(DataPath_Current, "/estimate.XLSX"),
sheet = "Sheet1",
range = "A2:J12",
guess_max = 100)
# just want to see what my table looks like
Ult_sum …Run Code Online (Sandbox Code Playgroud) 我有以下代码。我想更改箱线图的颜色,以便它们都具有相同的填充颜色(灰色)。另外,我想让 stat_summary 文本粘贴到每个条形图的底部,但 vjust 似乎只提供相对位置?
谢谢
boxp <- ggplot(mtcars, aes(as.factor(cyl), wt, fill=as.factor(am)) ) +
geom_bar(position = "dodge", stat = "summary", fun.y = "median") +
geom_boxplot(outlier.shape = NA, width=0.2, color = "black", position = position_dodge(0.9)) +
stat_summary(aes(label=round(..y..,2)), fun.y=median, geom="text", size=8, col = "white", vjust=8, position = position_dodge(0.9)) +
stat_summary(fun.y=mean, geom="point", shape=18, size=4, col="white", position = position_dodge(0.9)) +
labs(x = "Conditions", y = "Medians") +
scale_y_continuous(limits=c(0,7),oob = rescale_none) +
theme_bw()
boxp
Run Code Online (Sandbox Code Playgroud)
我有这个数据框:
df = {'DATE': [43390, 43599, 43605, 43329, 43440],
'STORE': [1, 1, 1, 2, 2],
'LYLTY_CARD_NBR': [1000, 1307, 1343, 2373, 2426],
'TXN_ID': [1, 348, 383, 974, 1038],
'PROD_QTY': [2, 3, 2, 5, 3],
'TOT_SALES': [6.0, 6.3, 2.9, 15.0, 13.8]}
transac = pd.DataFrame(df)
DATE STORE LYLTY_CARD_NBR TXN_ID PROD_QTY TOT_SALES
0 43390 1 1000 1 2 6.0
1 43599 1 1307 348 3 6.3
2 43605 1 1343 383 2 2.9
3 43329 2 2373 974 5 15.0
4 43440 2 2426 …Run Code Online (Sandbox Code Playgroud) 在阅读 KDnuggets 文章中的理解箱线图时。我找到了一个带有概率密度函数的 Boxplot 的详细图 (pdf)
我正在尝试绘制一个比较 Boxplot 和一个概率密度函数 (pdf),如下图所示
我知道分别绘制基本的箱线图和pdf。我对可视化的了解是最少的。我不是在问上面的图的精确复制,一个类似的细节图将不胜感激。
我对新的想法和方法持开放态度,并希望在开始深入研究之前先试探一下
如果是,是否可以用 Python 绘制上面的图,哪个包将用于绘制上面的图?有人能解释一下用 Python 绘制上面的图吗?我很高兴收到您的任何线索。
我使用以下代码创建了雨云图:
#雨图
dx = 'Time Point'; dy = 'Score'; ort = "v"; pal = "Set2"; sigma = .2;
f, ax = plt.subplots(figsize=(7, 5))
pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,
width_viol = .9, ax= ax, orient = ort, move = .2)
plt.title("")
plt.ylabel('Score', fontsize = 20)
plt.xlabel('', fontsize = 20)
plt.grid(color = 'w')
if savefigs:
plt.savefig('/Users/zeidanlab/Desktop/gv/rainplots/figure_tsc.png', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法使箱线图与分布斑点重叠。
我无法理解公式如何在R中起作用,公式是什么.那么,如果我有一个包含月度时间序列的向量,我怎么能创建一个盒子图,其中数据按季节逻辑划分?我想有12盒,每月一盒.
boxplot ×12
r ×9
ggplot2 ×5
python ×3
matplotlib ×2
seaborn ×2
legend ×1
outliers ×1
pandas ×1
python-3.x ×1
violin-plot ×1