首页 文章

无法在ggplot中正确显示大数字的图

提问于
浏览
0

我是R和ggplot的新手 . 我有一组大数字,似乎ggplot无法使用geom_bar()或geom_line()正确显示它 . 或许我错过了一些可以调整绘图比例的参数 . 请指出 . 谢谢!

For bar chart:

命令:

ggplot(income_exercise, aes(x= 'income2')) + geom_bar()

数据:
data of income category and count of people in each category

有问题的情节:

each bar is oversized, ggplot can't adjust the scale automatically

对于折线图:

命令: ggplot(income_exercise, aes(x= 'income2', y="cat_count")) + geom_line()

有问题的图表:

not display any data

1 回答

  • 0

    希望这会有所帮助 .

    library(ggplot2)
    df <- data.frame(income=c('Less than 10k', 
                               'Less than 15k',
                               'Less than 20k'),
                     freq=c(25441,
                              26794,
                              34873))
    # for bar chart
    ggplot(df, aes(x=income, y=freq)) + geom_bar(stat="identity")
    
    # for lines
    ggplot(df, aes(x=income, y=freq, group=1)) + geom_line() + geom_point()
    

相关问题