伙计们,我讨厌来这里,问愚蠢的问题,并接受错误,但这种情节杀死了我。ggplot 2中的多条形图
我需要绘制一个非常简单的数据集。
3列 - 年,民主党人,共和党人。 年份显示了当年的聚会 - 数字。
我向上帝发誓,我花了好几个小时,试图在R. 从简单的选项开始,并对我更具挑战性。
在ggplot简单的代码演示了上面一个可怕的阴谋:
ggplot(df,aes(x = Year,y = value)) +
geom_bar(aes(fill = variable), stat = "identity", position = "dodge")
我最后的尝试是融化(),但我又失败了
df <- melt(platforms[,c("Year", "Democrats", "Republicans")], id.vars = 1)
ggplot(df,aes(x = Year,y = value)) +
geom_bar(aes(fill = variable), stat = "identity", position = "dodge") + scale_y_log10()
错误Math.factor(X ,基地):'日志'没有意义的因素
我试图改变类它,但也失败了。 我用Google搜索了一下,我试过了 - 什么也没有。
在Excel中我杀死的东西最多,在5秒内完成。 enter image description here
请帮忙。
UPD。
platforms <- read.csv("Platforms(f3).csv", header = TRUE)
Year <- platforms$Year
Dems <- platforms$Democrats
GOP <- platforms$Republicans
Year Democrats Republicans
1 2016 26,058 35,467
2 2012 26,558 30,563
3 2008 25,997 23,585
4 2004 17,751 41,156
5 2000 24,220 34,555
6 1996 18,107 27,817
7 1992 8,555 28,531
8 1988 4,838 35,838
9 1984 37,231 27,383
10 1980 38,180 34,558
11 1976 21,202 20,463
12 1972 25,615 24,407
13 1968 16,791 10,013
14 1964 20,126 8,740
15 1960 16,098 10,680
16 1956 12,839 11,390
17 1952 8,878 5,988
18 1948 4,256 2,739
19 1944 1,366 4,216
20 1940 4,667 3,284
21 1936 2,310 3,030
22 1932 1,489 7,832
23 1928 5,613 7,401
24 1924 5,819 5,227
25 1920 7,118 6,391
26 1916 4,570 2,377
27 1912 4,696 3,393
28 1908 4,555 4,092
29 1904 3,058 2,254
30 1900 2,580 2,299
31 1896 1,929 1,933
32 1892 2,510 1,342
33 1888 1,379 2,391
34 1884 2,695 1,538
35 1880 692 1,471
36 1876 1,867 1,363
37 1872 633 1,270
38 1868 1,422 924
39 1864 506 895
40 1860 372 1194
41 1856 2,433 952
您收到downvotes的原因可能是因为你没有张贴重复的例子。你可以在这里发布“dput(平台)”吗?没有样本数据很难提供帮助。 –