夥計們,我討厭來這裏,問愚蠢的問題,並接受錯誤,但這種情節殺死了我。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(平臺)」嗎?沒有樣本數據很難提供幫助。 –