2015-03-02 90 views
1

我想結合ggplot和操作是這樣的:集成ggplot()與操作()採摘

library(ggplot2);library(manipulate) 

manipulate(
    ggplot(diamonds, aes(x = type, y = price)) + 
    geom_point(alpha = 1/10) + 
    geom_smooth(method = lm) 
    type = picker("carat","depth","table") 
) 

(其中操縱功能將改變X輸入,picker

但我正在一個Error: unexpected ')' in ")"


編輯1:固定的語法錯誤(請參見:({ ... )},

manipulate({ 
    ggplot(diamonds, aes(x = type, y = price)) + 
    geom_point(alpha = 1/10) + 
    geom_smooth(method = lm)}, 
    type = picker("carat","depth","table") 
) 

現在我越來越Don't know how to automatically pick scale for object of type manipulator.picker. Defaulting to continuous Error: Aesthetics must either be length one, or the same length as the dataProblems:type

+1

這只是一個語法錯誤。您需要在'geom_smooth(...)'之後和'type ='之前包含一個逗號。 – MrFlick 2015-03-02 22:18:12

回答

2

由於選擇器返回"carat"而不是carat,你應該使用aes_string,而不是aes

manipulate(
    ggplot(diamonds, aes_string(x = type, y = "price")) + 
    geom_point(alpha = 1/10) + 
    geom_smooth(method = lm), 
    type = picker("carat","depth","table") 
)