我是R新手,嘗試爲不同組別的分類變量(度)創建條形圖。這是我與迄今使用的代碼:使用ggplot2的百分比和圖形標籤中的條形圖
graph_data <- gss %>%
group_by(degree, owngun) %>%
summarise(total = n()) %>%
ungroup() %>%
mutate(percent = total/57061)
ggplot(graph_data, aes(x=degree, fill=owngun, y=percent) +
geom_bar(stat="identity") +
geom_text(size = 3, position = position_stack(vjust = 0.5))
第一部分的作品,我能夠創建一個新的變量,gunowners的百分比。然而,當我運行第二部分圖表中的變量,我得到以下錯誤信息:
> ggplot(aes(x=degree, fill=owngun, y=percent) +
+ geom_bar(stat="identity")
+ ggplot(graph_data, aes(x=degree, fill=owngun, y=percent) +
Error: unexpected symbol in:
" geom_bar(stat="identity")
ggplot"
> geom_bar(stat="identity") +
+ geom_text(size = 3, position = position_stack(vjust = 0.5))
Error in position_stack(vjust = 0.5) : unused argument (vjust = 0.5)
'ggplot(aes())'中缺少一個閉括號# – beetroot