我正在尝试获取蓝色图表,并获得绿色图表。
我的数据是:
lang <- c('spanish','italian','mix','english','portugues','others','french')
n <- c(22689,754,510,410,256,128,55)
percentage <- c(91.49,3.04,2.06,1.65,1.03,3.47,0.22)
count_bylanguage_top = data.frame(lang,n,percentage)
我正在使用此代码:
pie <- ggplot(count_bylanguage_top, aes(x = "", y=n, fill = factor(lang))) +
geom_bar(width = 1, stat = "identity") +
scale_fill_brewer(palette="blues") +
theme(axis.line = element_blank(),
plot.title = element_text(hjust=0.5)) +
labs(fill="lang",
x=NULL,
y=NULL,
title="Distribution of languages",
caption="Total Tweets with #Dante2018 hashtag")
pie + coord_polar(theta = "y", start=0)
答案 0 :(得分:1)
你需要使用&#34;蓝调&#34;而不是&#34;蓝调&#34;。通常,ggplot2包附带的所有调色板都是大写的(请参阅http://ggplot2.tidyverse.org/reference/scale_brewer.html#palettes或http://rstudio-pubs-static.s3.amazonaws.com/5312_98fc1aba2d5740dd849a5ab797cc2c8d.html)
至于你的代码,试试:
pie <- ggplot(count_bylanguage_top, aes(x = "", y=n, fill = factor(lang))) +
geom_bar(width = 1, stat = "identity") +
scale_fill_brewer(palette="Blues") + # use Blues here
theme(axis.line = element_blank(),
plot.title = element_text(hjust=0.5)) +
labs(fill="lang",
x=NULL,
y=NULL,
title="Distribution of languages",
caption="Total Tweets with #Dante2018 hashtag")
pie + coord_polar(theta = "y", start=0)