我作了几种不同的尝试来更改我正在构建的箱形图的异常值的填充颜色,但无济于事。任何帮助表示赞赏。到目前为止,这是我的代码...
# Load the dataset.
data <- read.csv("C:\\School\\Statistics\\bearWeight.csv")
# Initialize dataframe variable for both WEIGHT & Relative Frequency
WEIGHT <- data$WEIGHT
RelativeFrequency <- data$Relative.Frequency
# Load ggplot2
library(ggplot2)
bearWeightBoxPlot <- ggplot(data, aes(x=WEIGHT, y=RelativeFrequency, group = 1))
bearWeightBoxPlot <- bearWeightBoxPlot +
geom_boxplot(colour = "#3366FF", outlier.colour = "black",
outlier.shape = 24, outlier.fill = "red", outlier.size = 3)
bearWeightBoxPlot <- bearWeightBoxPlot +
geom_jitter(width = 0.2) +
coord_flip()
plot(bearWeightBoxPlot)
答案 0 :(得分:2)
我们需要参数outlier.fill
,其形状从21到25。
library(ggplot2)
p <- ggplot(mpg, aes(class, hwy))
p + geom_boxplot(outlier.colour = "black",
outlier.shape = 24,
outlier.fill = "red",
outlier.size = 3 # not actually needed
)
有关可能的形状的概述,请参见:www.cookbook-r.com
答案 1 :(得分:0)