Changing the xlim of numeric value causing error ggplot R

后端 未结 2 1684
粉色の甜心
粉色の甜心 2021-01-28 06:02

I have a grouped barplot produced using ggplot in R with the following code

ggplot(mTogether, aes(x = USuniquNegR, y = value, fill = variable)) +
geom_bar(stat =         


        
相关标签:
2条回答
  • 2021-01-28 06:35

    You need to remove the cbind from

    together<-data.frame(cbind(USperReasons,USperReasonsNY,USuniquNegR))
    

    because str(together) tells that all three columns are factors.

    With

    together <- data.frame(USperReasons, USperReasonsNY, USuniquNegR)
    

    the plot looks reasonable to me (without having to use ylim or xlim).

    So, the error was not within ggplot2 but in data preparation. Therefore, please, provide a full working example which can be copied, pasted and run when asking a question next time. Thank you.

    0 讨论(0)
  • 2021-01-28 06:52

    The problem is that you are cbind()ing your column vectors together, which converts the numbers to characters. Fix that and the rest should fix itself.

    together<-data.frame(USperReasons,USperReasonsNY,USuniquNegR)
    
    0 讨论(0)
提交回复
热议问题