2017-05-08 3 views
0

Ich möchte ein Facettenplot mit 4 Punktdiagrammen erstellen, jedoch gibt mein Code unten den Fehler "Error in p + facet_grid(party ~ state) : non-numeric argument to binary operator" zurück. Irgendwelche Ideen warum?Fehler "nicht numerisches Argument zu binärem Operator" mit plotly facet_grid

# plotly minimum reproducible example 
library(plotly) 

# create dummy data set 
state <- c("MA", "MA", "CA", "CA") 
party <- c("Republican", "Democrat", "Republican", "Democrat") 
age <- c(45,32,28,76) 
FICO <- c(675, 789, 425, 690) 
df <- data.frame(state, party, age , FICO) 

# Create 4 scatter plots 
p <- plot_ly(data = df, x = ~age, y = ~FICO) 
p <- p + facet_grid(party ~ state) 
print(p) 

Vielen Dank!

Antwort

1

Der Fehler kommt vom Versuch, + ein facet_grid zu einem Plotly-Objekt. Soweit ich weiß, ist dies keine gültige Operation für ein plotly-Objekt. Wenn Sie das Facettengitterdiagramm nur mit ggplot2 erstellen, können Sie in der Grafik ggplotly aufrufen, um die Interaktivität von plotly anzuwenden.

# plotly minimum reproducible example 
library(plotly) 

# create dummy data set 
state <- c("MA", "MA", "CA", "CA") 
party <- c("Republican", "Democrat", "Republican", "Democrat") 
age <- c(45,32,28,76) 
FICO <- c(675, 789, 425, 690) 
df <- data.frame(state, party, age , FICO) 

# Create 4 scatter plots 
p <- ggplot(df, aes(x=age, y=FICO)) + 
    geom_point() + 
    facet_grid(party ~ state) 

ggplotly(p) 
Verwandte Themen