2014-05-15 77 views
-5

我有此TESTDATA:ggplot圖表中,x =日期,Y =值,值

 date  cpu_user cpu_id test1 test2 test3 test4 
1 1386716402  U  U  U  U  U 31 
2 1386716702  0 0.06 99.95 0.02 91.93 29 
3 1386717002  0.01 0.04 99.97 0.03 19.46 29 
4 1386717302  0.01 0.05 99.96 0.04 92.54 29 
5 1386717602  0 0.04 99.97 0.04  U 29 
6 1386717902  0 0.05 99.96 0.02 99.86 29 

我想例如與日期在x和其它一freqpoly圖表(cpu_udercpu_id,.... )在y。有人有想法嗎?

謝謝,最好問候!

+0

你嘗試過這麼遠嗎?順便說一句,因爲您將字符(U)與數字數據一起存儲在多列中,它們將被轉換爲「字符」,這對繪圖沒有任何意義。 U是否意味着NA? –

+0

請參閱以下問題的以下問題的回答:[1](http://stackoverflow.com/questions/23319559/r-ggplot-focusing-in-region-and-different-scale-in-one-axis/ 23320069)/ [2](http://stackoverflow.com/questions/23641636/insert-graph-legend-using-ggplot/23641788#23641788) – Jaap

+0

是ü表示不適用 – user3181885

回答

0
d <- read.table(text=readClipboard(), header=TRUE, stringsAsFactors = T, 
       na.strings = 'U') 
df <- melt(d, id.var='date') 
ggplot(aes(x=date, y=value), data = df) + 
    geom_bar(aes(fill = variable), stat = 'identity', position = 'dodge') 

bar chart

ggplot(aes(x=factor(date), y=value), data = df) + 
    geom_bar(stat = 'identity', position = 'dodge') + 
    facet_grid(variable~., scales = 'free_y', drop = F) + 
    theme(axis.text.x = element_text(angle = 45, vjust = 1.1, hjust = 1.05)) 

faceting option

+0

非常感謝你...可以你爲frecpoly發佈一個例子嗎? – user3181885

+0

@ user3181885恐怕你不能沒有頻率數據。你爲每個測試提供了一個單獨的條目。 geom_path改爲?請參閱[ggplot文檔](http://docs.ggplot2.org/0.9.3.1/geom_freqpoly.html)。 –

+0

嗯有沒有機會創建與我的testdate這樣的圖表 - >(例如)[鏈接](http://www.datameer.com/documentation/download/attachments/33227118/Line_Chart.png?version= 1&modificationDate = 1310634467000&api = v2) – user3181885