R-gg图省略NA

R-gg图省略NA,r,R,我试图在R中绘制ggplots。我的数据集有几行,其中一个或多个变量为NA。如何使NA不出现在图表上? 这是我的密码: met$marker_Degree2 = factor(met$marker_Degree, levels=c("none", "weak")) p4 <- ggplot(met, aes(factor(marker_Degree2), avgtsh)) p4 + ggtitle('Serum marker and Tumor marker') + geom_point(

我试图在R中绘制ggplots。我的数据集有几行,其中一个或多个变量为NA。如何使NA不出现在图表上? 这是我的密码:

met$marker_Degree2 = factor(met$marker_Degree, levels=c("none", "weak"))
p4 <- ggplot(met, aes(factor(marker_Degree2), avgtsh))
p4 + ggtitle('Serum marker and Tumor marker') +
geom_point(shape=21, size=4, aes(color=factor(marker_Degree2))) +
scale_color_manual(values = c("orange", "green")) +
theme_bw() +
xlab("Marker Tissue Staining Degree") +
ylab("Mean marker Level in Serum")
met$marker\u Degree2=因子(met$marker\u Degree,级别=c(“无”、“弱”))
p4这里有一个例子

mydata <- data.frame(income=c(50000,NA,10000,30000), y=c("male", "female", NA, "female"))
p <- ggplot(mydata, aes(x,z))
p + geom_point()

mydata处理您提供的示例的一种方法如下:

mydata <- data.frame(income=c(50000,NA,10000,30000), y=c("male", "female", NA, "female"))
p <- ggplot(mydata, aes(income,y))
p + geom_point(na.rm = TRUE) + ylim(labels=c("male", "female"))

为您的数据提供一个示例。默认情况下,在
ggplot
中,NA应该被省略,仅适用于数字
mydata <- data.frame(income=c(50000,NA,10000,30000), y=c("male", "female", NA, "female"))
p <- ggplot(mydata, aes(income,y))
p + geom_point(na.rm = TRUE) + ylim(labels=c("male", "female"))
ggplot(na.omit(mydata), aes(income,y))