Home > Blockchain >  Data must either be a data frame or a matrix , in ggplot2
Data must either be a data frame or a matrix , in ggplot2

Time:05-07

I am running this code block, it is a simple ggplot2 lolipop graph but it is throwing me an error and I do not know how is this not a dataframe despite converting it into it

x=c('KNN','Log.reg','Rand.For','SVM','Naiv.Bay','DeepLearn.')
z=c(0.922,0.8154,0.772,0.8064,0.664,0.574)


# Create data
data <- data.frame(
  Model=x,
  AUC=z
)
data<-as.data.frame(data)
# plot
lol<-ggplot(data, aes(x=Model, y=AUC))  
  geom_segment( aes(x=Model, xend=Model, y=0, yend=AUC))  
  geom_point( size=5, color="red", fill=alpha("orange", 0.3), alpha=0.7, shape=21, stroke=2)
  theme_light()  
  theme(
    panel.grid.major.x = element_blank(),
    panel.border = element_blank(),
    axis.ticks.x = element_blank()
  )  
  xlab("Models")  
  ylab("AUC")
lol geom_text(aes(label=data$AUC),size=4)

Error in alpha("orange", 0.3) : Data must either be a data frame or a matrix

CodePudding user response:

Okay , I think the answere is you need to unload the library 'psych' because it conflicts with ggplot2 somehow. Hope this helps.

CodePudding user response:

You miss a after geom_point....

x=c('KNN','Log.reg','Rand.For','SVM','Naiv.Bay','DeepLearn.')
z=c(0.922,0.8154,0.772,0.8064,0.664,0.574)


# Create data
data <- data.frame(
  Model=x,
  AUC=z
)
data<-as.data.frame(data)

class(data)
# plot
lol<-ggplot(data, aes(x=Model, y=AUC))  
  geom_segment( aes(x=Model, xend=Model, y=0, yend=AUC))  
  geom_point( size=5, color="red", fill=alpha("orange", 0.3), alpha=0.7, shape=21, stroke=2) 
theme_light()  
  theme(
    panel.grid.major.x = element_blank(),
    panel.border = element_blank(),
    axis.ticks.x = element_blank()
  )  
  xlab("Models")  
  ylab("AUC")
lol geom_text(aes(label=data$AUC),size=4)

enter image description here

  • Related