我想创建一个带有降序条的条形图,在下面的图中,由于 NA 出现在“a1”向量中的第二个位置,它在创建图时最后被推送。但是,我希望 NA 栏只出现在第二个位置,请在这里帮助我,因为我想在不修改数据的情况下实现这一点。
library(ggplot2)
library(plotly)
a1 = c("A",NA,"B","C","D","F")
b1 = c(165,154,134,110,94,78)
a12 = data.frame(a1,b1,stringsAsFactors = FALSE)
pp1 <<- ggplot(a12 , aes(x = reorder(a1,-b1), y = b1,text=paste("User:
<br>",a1, "<br> Days: <br>", round(b1)))) +
geom_bar(stat = "identity", fill = "#3399ff" ) +
scale_y_continuous(name = "Time") +
scale_x_discrete(name ="Employee")
ggplotly(pp1, tooltip="text",height = 392)