2010-07-16 167 views
4

從下面的XML代碼:交互圖中的R用rggobi

<?xml version = "1.0"?> 
<Company > 
<shareprice> 
    <timeStamp> 12:00:00.01</timeStamp> 
    <Price> 25.02</Price> 
</shareprice> 

<shareprice> 
     <timeStamp> 12:00:00.02</timeStamp> 
    <Price> 15</Price> 
</shareprice> 



    <shareprice> 
     <timeStamp> 12:00:01.025</timeStamp> 
     <Price> 15.02</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:01.031</timeStamp> 
     <Price> 18.25</Price> 
    </shareprice> 



    <shareprice> 
     <timeStamp> 12:00:01.039</timeStamp> 
     <Price> 18.54</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:01.050</timeStamp> 
     <Price> 16.52</Price> 
    </shareprice> 


    <shareprice> 
     <timeStamp> 12:00:02.01</timeStamp> 
     <Price> 17.50</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:03.01</timeStamp> 
     <Price> 25.02</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:05.02</timeStamp> 
     <Price> 30</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:11.025</timeStamp> 
     <Price> 32.25</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:12.031</timeStamp> 
     <Price> 26.05</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:15.039</timeStamp> 
     <Price> 18.54</Price> 
    </shareprice> 

    <shareprice> 
     <timeStamp> 12:00:19.050</timeStamp> 
     <Price> 16.52</Price> 
    </shareprice> 


    <shareprice> 
     <timeStamp> 12:01:02.01</timeStamp> 
     <Price> 17.50</Price> 
    </shareprice> 
</Company> 

,並使用下述R代碼:

library(ggplot2) 
library (XML) 
test.df <- xmlToDataFrame(file.choose()) 
test.df 
sapply(test.df, class) 
test.df$timeStamp <- strptime(as.character(test.df$timeStamp), "%H:%M:%OS") 
test.df$Price <- as.numeric(as.character(test.df$Price)) 
sapply(test.df, class) 
options("digits.secs"=3) 
summary (test.df) 
with(test.df, plot(timeStamp, Price)) 
sd (test.df$Price) 
mean(test.df$timeStamp) 
test.df$timeStamp <- test.df[1,"timeStamp"] + cumsum(runif(7)*60) 
summary(test.df) 
qplot(timeStamp,Price,data=test.df,geom=c("point","line")) 
Price <- summary(test.df$Price) 
print (Price) 

我想創建交互式圖形,將允許用戶點擊一個點,並獲得關於該點的價值的信息(例如,如果價值跳動的原因如此),我希望能夠將這個交互式圖形放在網頁上。有人建議使用GGOBI來做到這一點,而另一些人則說可以留在R中並使用rggobi庫。由於我沒有這方面的經驗,我以爲我會直接或要求一些指針或特定的資源(一個可以花幾年搜索網絡,沒有找到任何東西)

下圖我想打印出價格摘要。此刻,我在Windows上的BATCH文件中運行代碼,它將圖形以pdf文件形式返回,但不是摘要打印。是否有辦法設置代碼/ BATCH文件,以便它可以生成交互式圖形和摘要?

+0

Ggobi與網絡無關。你正在看錯技術。 – 2010-07-16 23:24:47

+3

對於未來的帖子,如果不是發佈xml,而是將其加載到R中,應用所需的所有轉換,然後將'dput(dest.df)'的輸出粘貼到您的問題中,那將會很好。這樣可以節省答覆者幾個步驟。 – JoFrhwld 2010-07-17 15:14:22

+0

我會在下次嘗試。我正確地假設我可以運行dput(測試。df)在我有R代碼的末尾粘貼結構(列表(....)到問題中? – 2010-07-18 17:14:34

回答

2

安東尼,我假定你指的是ID在GGobi中可用的功能。您可以使用工具>保存顯示描述DescribeDisplay包在CRAN上可用,以便將GGplot圖導出/導入R.您將需要DescribeDisplayggplot2或「內置」graphics包,即可以使用qplotplot來獲取圖表。

一旦保存,顯示內容可通過導入:看the link =)

關於「點擊並獲得-信息」功能 - RApache是​​不會幫你要麼!有identifylocator函數可以與graphics一起使用,並且可以幫助您在R中使用click-and-get-info(請參閱Maindonald,JH - 「將R用於數據分析和圖形」 - 3.4。圖區域,它是免費的,並且可用here),但是如果您打算在網絡上執行更爲雄心勃勃的任務,請參閱HTML <map><area>標記,這裏是an example。那麼我想你會做一些JavaScript魔術(定義座標和東西),如果我注意到的話,這很有雄心。

另請參閱:graphics::textggplot2::geom_text