-1
head(x)
    Region  Type       Date count
1 Americas Point 2011-10-26     1
2 Americas Point 2011-10-27     2
3 Americas Point 2011-10-31     1
4 Americas Point 2011-11-01     1
5 Americas Point 2011-12-05     1
6 Americas Point 2011-12-07     1

dput(x)
structure(list(Region = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = "Americas", class = "factor"), Type = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Point", class = "factor"), 
    Date = structure(c(15273, 15274, 15278, 15279, 15313, 15315, 
    15316, 15320, 15341, 15342, 15351, 15358, 15370, 15390, 15392, 
    15405, 15407, 15411, 15418, 15421, 15433, 15467, 15470, 15482, 
    15495, 15497, 15503, 15517, 15530, 15551, 15554, 15582, 15586, 
    15589, 15593, 15601, 15602, 15610, 15615, 15616, 15624, 15643, 
    15645, 15656, 15663, 15664, 15665, 15672, 15673, 15677, 15678, 
    15679, 15680, 15684, 15686, 15693, 15694, 15698, 15699, 15705, 
    15706, 15707, 15712, 15713, 15714, 15719, 15720, 15721, 15727, 
    15736, 15740, 15741, 15742, 15743), class = "Date"), count = c(1L, 
    2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("Region", 
"Type", "Date", "count"), row.names = c(NA, -74L), class = "data.frame")

我正在尝试构建一个堆栈条形图,如下所示:

ggplot(x, aes(Date, count, group=Region)) + 
   geom_bar(aes(fill=Type, width=0.3),stat="identity", position="stack") + 
   scale_x_date(breaks = "1 month", 
                minor_breaks = "2 weeks", 
                labels=date_format("%b-%y")) +
   geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
   facet_wrap(~Region)

默认情况下,我会看到一些缺失的点,但是当我拉伸绘图窗口时,会出现点。我真的需要图表中的所有点,否则看起来我错过了报告数据。任何建议我该如何解决这个问题,以便我看到图表上的所有数据点。我的窗口大小是 500 x 500。

4

1 回答 1

1

事实上,通过增加屏幕尺寸会出现更多的条形图。您无法在 R 控制台的小窗口中看到它们,因为条形的宽度太小。但是当你保存它时,可以在输出中看到这些条:

plot <- ggplot(x, aes(Date, count, group=Region)) + 
geom_bar(aes(fill=Type, width=0.3),stat="identity", position="stack") + 
scale_x_date(breaks = "1 month", 
            minor_breaks = "2 weeks") +
geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
facet_wrap(~Region)

ggsave("test.pdf",plot )

要查看 R 控制台中的所有点,请增加宽度,例如:

(plot <- ggplot(x, aes(Date, count, group=Region)) + 
geom_bar(aes(fill=Type, width=1),stat="identity", position="stack") + 
scale_x_date(breaks = "1 month", 
            minor_breaks = "2 weeks") +
geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
facet_wrap(~Region))
于 2013-02-13T12:57:07.640 回答