在绘制多个箱形图时如何对x使用特定的离散值

问题描述 投票:1回答:2

我正在尝试对框“ alcagbi”的“是”和“否”进行编码。我得到的箱形图表示是,否和不适用,我要删除不适用值。

看起来像这样

sf36mcs:4.45、21.4、34.9、14.3、74.1、66.4等,因此是连续的

alcagbi:是,是,不适用,否,是,不适用,所以是离散的

library(tidyverse)

ggplot(data=WHS, mapping=aes(alcagbi, sf36mcs))+
  geom_boxplot()

My box plots so far

还如何获得它,以便y轴仅显示正值?

我是一名学生,仍在学习此软件,因此,感谢您提供任何反馈意见。谢谢!

r filter boxplot
2个回答
0
投票

我们可以做

library(dplyr)
library(ggplot2)
WHS %>%
   filter(alcagbi != "N/A") %>% 
   droplevels() %>%
   ggplot(mapping = aes(alcagbi, sf36mcs)) + geom_boxplot()

0
投票

[Akrun过滤了N / A,所以我要借用该代码,但过滤掉负数

library(dplyr)
library(ggplot2)
WHS %>%
    filter(alcagbi != "N/A",
           sf36mcs >= 0) %>% ###This is the addition
    droplevels() %>%
    ggplot(mapping = aes(alcagbi, sf36mcs)) + geom_boxplot()

如果要排除0,请使> =简单>

© www.soinside.com 2019 - 2024. All rights reserved.