我有一个包含日期,磁盘读取和磁盘写入数据的数据框。我能够创建堆栈图表,但xaxis上的日期是不可读的。 qplot中是否有选项来缩放图表或者不显示所有日期或其他内容?我一直在看这个很长一段时间,我找不到答案。
我先融化它
app1_diskIO.M<-melt(app1_diskIO.M, id=c("Date2"))
qplot(x = factor(Date2), y = value, data = app1_diskIO.M, geom = "bar", fill = variable, main="DISK IO", xlab="Date", ylab="Disk IO")
数据框如下所示:
Date2 DiskReads DiskWrites
1 2011-12-06 136382.2 78961.0
2 2011-12-07 146277.0 77802.0
3 2011-12-08 141123.6 76219.0
4 2011-12-09 139219.8 77649.4
5 2011-12-10 72101.1 35258.6
6 2011-12-11 229445.9 92316.6
7 2011-12-12 175886.7 86087.0
8 2011-12-13 134958.3 76605.6
9 2011-12-14 133972.1 75141.4
10 2011-12-15 147175.2 77189.7
11 2011-12-16 143542.3 78155.9
12 2011-12-17 152579.1 68395.2
13 2011-12-18 168667.7 69720.1
14 2011-12-19 152328.6 75994.2
15 2011-12-20 135061.8 75271.6
16 2011-12-21 153455.0 78197.5
17 2011-12-22 130020.8 73369.7
18 2011-12-23 131423.6 73484.9
19 2011-12-24 135285.6 65081.4
20 2011-12-25 137185.4 63334.8
21 2011-12-26 132612.9 70484.4
22 2011-12-27 155396.9 79239.1
23 2011-12-28 151587.5 77986.5
24 2011-12-29 122076.5 71575.5
25 2011-12-30 146888.8 75376.3
26 2011-12-31 141285.5 69737.8
27 2012-01-01 206306.6 78059.4
28 2012-01-02 134002.4 73062.5
29 2012-01-03 137753.8 76947.4
30 2012-01-04 150655.8 78836.3
31 2012-01-05 151750.3 79300.9
32 2012-01-06 141464.8 77529.4
33 2012-01-07 137667.3 66344.8
34 2012-01-08 120998.5 60582.4
35 2012-01-09 133422.4 73688.3
36 2012-01-10 134247.7 75664.5
37 2012-01-11 146243.5 79042.2
38 2012-01-12 178738.2 84199.7
39 2012-01-13 145564.8 77908.2
40 2012-01-14 135966.8 65900.9
41 2012-01-15 136448.4 63339.9
42 2012-01-16 186109.9 83348.6
43 2012-01-17 146906.5 78645.6
44 2012-01-18 106343.0 69313.6
45 2012-01-19 197205.6 88411.6
46 2012-01-20 132950.1 73078.0
47 2012-01-21 137488.1 68711.5
答案 0 :(得分:1)
如何将日期旋转为垂直,这使它们更清晰:
qplot(x = factor(Date2), y = value, data = app1_diskIO.M,
geom = "bar", fill = variable, main = "DISK IO",
xlab = "Date", ylab = "Disk IO") +
opts(axis.text.x = theme_text(angl e =-90))
您还可以缩小字体大小(这是您的缩放比例吗?),但这并不会让它更容易阅读。为此,请在size
opts
参数
qplot(x = factor(Date2), y = value, data = app1_diskIO.M,
geom = "bar", fill = variable, main = "DISK IO",
xlab = "Date", ylab = "Disk IO") +
opts(axis.text.x = theme_text(angle = -90, size = 5))
要删除X轴上的所有刻度线和标签(因此您没有按要求显示任何日期,也许您可能会使用图形编辑器将其他东西放在那里?),试试这样:
qplot(x = factor(Date2), y = value, data = app1_diskIO.M,
geom = "bar", fill = variable, main = "DISK IO",
xlab = "Date", ylab = "Disk IO") +
opts(axis.ticks = theme_blank(), axis.text.x = theme_blank())
更新:要空出x轴标签,请按照您的要求每十天说一次,试试这个:
app1_diskIO.M$Date2 <- as.Date(app1_diskIO.M$Date2)
qplot(x = Date2,
y = value, data = app1_diskIO.M,
geom = "line", colour = variable,
main="DISK IO", xlab="Date",
ylab="Disk IO") +
scale_x_date(breaks = "10 days") +
opts(axis.text.x = theme_text(angle = -90))
哪个应该给你:
有用的网站,提供了做这类内容的优秀说明:http://wiki.stdout.org/rcookbook/Graphs/Axes%20(ggplot2)/
ggplot2 0.9中的更新指南非常方便,有很多很好的例子:http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf