试图用“字符”绘制R中的条形图。在X轴上和“因素”上在y轴上

发布于 2025-01-30 09:37:13 字数 662 浏览 1 评论 0原文

学位:我,BE,EMP,NAME,EIM,MA,MA,MH,OE,RC,CFS,AS

收入:73926,97410,74179,74179,75635,78866,54000,54000,44800,45000,45000

结构(list = c(“ me”,“ be”,“ emps”,“ name”,“ eim”, “ EC”,“ MA”,“ MH”,“ OE”,“ RC”,“ CFS”,“ AS”),收入= C(73926,, 97410,74179,75635,78866,54000,44800,45000,46300,46400, 46500,47000)),class = c(“ tbl_df”,“ tbl”,“ data.frame”),row.names = c(na,, -12L))

'' barplot(数据$度,数据$收入) '''

新手在这里。我正在尝试复制下面的条形图,但是在R中,我确实在努力挣扎,因为所有尝试都以错误的“参数不是数字或逻辑”结尾。不确定下一步该做什么和任何建议将不胜感激。

Degrees: ME, BE, EMPS, NAME, EIM, EC, MA, MH, OE, RC, CFS, AS

Income: 73926, 97410, 74179, 75635, 78866, 54000, 44800, 45000, 46300, 46400, 46500, 47000

structure(list(Degree = c("ME", "BE", "EMPS", "NAME", "EIM",
"Ec", "MA", "MH", "OE", "RC", "CFS", "AS"), Income = c(73926,
97410, 74179, 75635, 78866, 54000, 44800, 45000, 46300, 46400,
46500, 47000)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-12L))

'''
barplot(data$Degrees, data$Income)
'''

Newbie to R here. I am trying to replicate the bar chart below, but in R. Really struggling with this as all attempts end with the error 'argument is not numeric or logical'. Unsure what to do next and any advice would be appreciated.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2025-02-06 09:37:13

寻找ggplot2

尝试创建代码strucutre的软件包信息,以便您可以编辑某些特征,例如文本大小等:

ggplot(df)+
        geom_col(aes(x = Degree, 
                     y = Income),
                 fill = "blue",
                 width = 0.7)+
        theme_classic() +
        ggtitle("Graph title",
                subtitle = "Subtitle")+
        labs(x = "X axis title",
             y = "Y axis title")+
        theme(axis.title = element_text(size = 15, face = "bold"),
              axis.text = element_text(size = 10),
              plot.title = element_text(size = 20, hjust = 0.5),
              plot.subtitle = element_text(size = 15, hjust= 0.5))
    

“

Look for ggplot2 package information

Tryed to create the code strucutre so you can edit some characteristc like texts size and etc:

ggplot(df)+
        geom_col(aes(x = Degree, 
                     y = Income),
                 fill = "blue",
                 width = 0.7)+
        theme_classic() +
        ggtitle("Graph title",
                subtitle = "Subtitle")+
        labs(x = "X axis title",
             y = "Y axis title")+
        theme(axis.title = element_text(size = 15, face = "bold"),
              axis.text = element_text(size = 10),
              plot.title = element_text(size = 20, hjust = 0.5),
              plot.subtitle = element_text(size = 15, hjust= 0.5))
    

enter image description here

枕梦 2025-02-06 09:37:13

您也可以尝试:

barplot( df$Income ~ df$Degree, col = "blue")

“在此处输入图像描述”

我不确定如何执行此操作(我主要使用ggplot2,而不是基本r图),但这是我为弄清楚它所做的,以防万一它有助于任何未来的终点。

  1. 我在代码中选择了单词barplot,然后单击F1以获得该功能的帮助。您还可以在控制台中键入?barplot

  2. r帮助文件具有某种格式,可能需要一些习惯。前注的“用法”部分是它所采取的论点。底部的“示例”部分通常显示使用该函数的正常方式。它显示barplot(gnp〜年,data = longley)具有与其他R函数相同的语法代码> y〜x 表示,取决于功能,“回归或绘图y作为x的函数”

You might also try:

barplot( df$Income ~ df$Degree, col = "blue")

enter image description here

I wasn't sure how to do this (I mostly use ggplot2, not base R plots), but here's what I did to figure it out, in case it helps for any future endevours.

  1. I selected the word barplot in the code and clicked F1 to get the help for the function. You can also type ?barplot in the console.

  2. R help files have a certain format that might take some getting used to. The "Usage" section on the top notes the arguments it takes. The "Examples" section at the bottom typically shows the normal way(s) to use the function. It shows barplot(GNP ~ Year, data = longley) which has the same syntax as some other R functions like lm and plot, where y ~ x means, depending on the function, "regress or plot y as a function of x."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文