R 从一个浓缩条形图创建多个条形图

R 从一个浓缩条形图创建多个条形图,r,plot,ggplot2,bar-chart,R,Plot,Ggplot2,Bar Chart,我想知道是否有一种有效的方法可以从一张表中生成较小的条形图。我的目标是生成干净的图形,而不是一个难以阅读的密集图形。有没有一种方法可以在不使用extesive编码的情况下做到这一点?源表位于一个data.frame对象类型中。这里有四个不同的绘图,也许其中一个是您喜欢的 library(ggplot2) # plotting and the diamonds data set library(dplyr) # needed for the filter function # Unwa

我想知道是否有一种有效的方法可以从一张表中生成较小的条形图。我的目标是生成干净的图形,而不是一个难以阅读的密集图形。有没有一种方法可以在不使用extesive编码的情况下做到这一点?源表位于一个
data.frame
对象类型中。

这里有四个不同的绘图,也许其中一个是您喜欢的

library(ggplot2)  # plotting and the diamonds data set
library(dplyr)    # needed for the filter function


# Unwanted 'dense' graph
g1 <- 
  ggplot(diamonds) + 
  aes(x = cut, fill = color) + 
  geom_bar() + 
  ggtitle("g1: stacked bar plot")
library(ggplot2)#绘图和菱形数据集
库(dplyr)#过滤器功能所需
#不需要的“密集”图

g1如果你能发布一篇文章,那会有很大帮助,但是在
ggplot
中可以找到一些选项。特别是方面可能是您正在寻找的。
# or
g2 <- 
  ggplot(diamonds) + 
  aes(x = cut, fill = color) + 
  geom_bar(position = position_dodge()) + 
  ggtitle("g2: dodged bar plot")
# different option, layered bars 
g3 <- 
  ggplot() + 
    aes(x = cut, fill = color) + 
    geom_bar(data = filter(diamonds, color == "D"), width = 0.90) +
    geom_bar(data = filter(diamonds, color == "E"), width = 0.77) + 
    geom_bar(data = filter(diamonds, color == "F"), width = 0.63) + 
    geom_bar(data = filter(diamonds, color == "G"), width = 0.50) + 
    geom_bar(data = filter(diamonds, color == "H"), width = 0.37) + 
    geom_bar(data = filter(diamonds, color == "I"), width = 0.23) + 
    geom_bar(data = filter(diamonds, color == "J"), width = 0.10) +
    ggtitle("g3: overlaid bar plot")
# facet plot
g4 <- 
  ggplot(diamonds) + 
  aes(x = cut) + 
  geom_bar() + 
  facet_wrap( ~ color)