ggplot2比例条形图:每条仅彩色17级中的1级

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

我对R和SO很陌生,希望您对此有所帮助。

我有一个具有17个级别的factor类数据。我正在使用library(ggplot2)geom_bar(position="fill")创建比例条形图。代码和输出/图在下面。

[基本上,这很好,但我想做的是再创建17个这样的地块,以突出显示其中一个级别(即一种颜色)保持不变,而其余部分变灰为一种将一个级别与其他级别区分开的方法。因为有17个级别,并且颜色非常相似,所以现在很难区分一些级别。

我希望这是有道理的-很高兴编辑并提供更多信息。我希望能对此提供任何指导或帮助。非常感谢!


代码

# libraries
library(tidyverse) # for the plot
library(ggplot2) # for the plot
library(scales) # for the x-axis scaling
library(lubridate) # for the "POSIXct" and "POSIXt" class

#data classes
class(df.forum$p.date) # "POSIXct" "POSIXt"
class(df.forum$p.forum) # factor

# the plot
df.forum %>% 
  ggplot(aes(x = p.date, fill = factor(p.forum))) +
  geom_bar(position = "fill", stat = "count", show.legend = TRUE) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1,vjust = 0.2)) +
  scale_x_datetime(date_breaks = "1 month",labels = date_format("%b %Y"), limits = c(mdy_hms("10/1/13 20:00:00"),mdy_hms("5/1/14 20:00:00")))

情节

ggplot2 proportional bar graph plotted

r ggplot2 colors geom-bar
1个回答
0
投票

我认为用途gghighlight将满足您的需求。

这里是使用iris数据集的示例:

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))+
  geom_point()+
  facet_wrap(~Species)+
  gghighlight()

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