2015-10-10 52 views
0

林在我的新的數據集工作,我總是只會繪製因子?

options(StringsAsFactors = FALSE) 

開始,現在遇到的問題即時消息是,如果字符串作爲因素選項設置爲TRUE R將只繪製的數據我設置。

每當我嘗試使用Stringsasfactors = FALSE繪圖時,它會給我下一個錯誤消息。

plot(Data$Jobs, Data$RXH) 
Error in plot.window(...) : need finite 'xlim' values 
In addition: Warning messages: 
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 
2: In min(x) : no non-missing arguments to min; returning Inf 
3: In max(x) : no non-missing arguments to max; returning -Inf 

但是,當我設置Stringsasfactors TRUE它繪製它沒有問題......

這是腳本。

#Setting WD. 

getwd() 
setwd("C:/Windows/System32/config/systemprofile/Documents/R proj") 


options(stringsAsFactors = F) 
get <- read.csv("WorkExcelR.csv", header = TRUE, sep = ",") 
Data <- na.omit(get) 

這是數據$作業和數據$ RXH

> Data$Jobs 
[1] "Playstation" "RWC Heineken" "Jagermeister" "RWC Heineken" 
[5] "RWC Heineken" "RWC Heineken" 
> Data$RXH 
[1] 90 90 100 90 90 90 
+3

'plot(factor(Data $ Jobs),Data $ RXH)' – Roland

回答

1

你能說明問題的事實是有plot.factor功能而不plot.character功能造成的。您可以通過鍵入查看可用的plot.的方法:

methods(plot) 

這不是特別的幫助頁面?plot描述,但有一個單獨的幫助頁面?plot.factor。 R中的函數根據它們的參數進行調度:S3僅基於它們的第一個參數的類和S4方法基於它們的參數簽名來執行功能。從某種意義上說,plot.factor函數詳細闡述了該策略,因爲它然後根據第二個參數的類別分派到不同的繪圖例程,假定它與位置匹配或被命名爲y

您有幾個選擇:強制繪圖方法,然後需要使用:::中綴函數進行caled,因爲plot.factor未導出或自己執行強制操作或調用更具體的繪圖類型。

graphics:::plot.factor(Data$Jobs, Dat 
plot(factor(Data$Jobs), Data$RXH) 
boxplot(Data$RXH ~Data$Jobs) # which is the result if x is factor and y is numeric 
+0

非常感謝!這幫助了我! ! –