[英]change color of text and chart - ggplot2 in r
我想讓文本和 geom_area 填充特定的顏色。 顏色代碼為:#795fc6
我試過了,但它不起作用,並且 fill=0.1 根本不是正確的顏色。
我的數據集由 4662 個觀察值的 26 個變量組成。 對於這個 plot 我只需要兩個變量。 anaylysis_date(日期格式 YYYY-MM-DD)y 軸是分析期間每天發生的所有觀察值的總和。
這是分析日期列的可重現示例:
df = c("2017-11-12", "2018-03-28", "2018-06-30", "2018-06-22", "2018-09-24" ,"2018-11-21")
這是我現在的 plot:
ggplot(data = DatasetApp, aes(x=analysis_date, fill=0.1)) +
geom_area(stat="bin",axis.text.x=col=c("#795fc6")) +
labs(x="Date",y="Number of Observations", title = "Number of observations pre and post GDPR", col="#795fc6")+
geom_vline(xintercept = as.numeric(DatasetApp$analysis_date[GDPR_date]), color=c("#5034c4"))+
theme_minimal()
所以簡而言之,您希望 plot 完全是紫色的。
可以使用aes
參數之外的fill
參數更改區域填充。 文本 colors 設置在theme
function 內,帶有 arguments text
(更改標題和軸標題的顏色)和axis.text
(更改軸標簽)。
數據
df <- data.frame(date = as.Date(c("2017-11-12", "2018-03-28",
"2018-06-30", "2018-06-22",
"2018-09-24" ,"2018-11-21"),
format = "%Y-%m-%d"))
代碼
ggplot(data = df, aes(x=date)) +
geom_area(stat="bin", fill = "#795fc6") +
labs(x="Date",
y="Number of Observations",
title = "Number of observations pre and post GDPR")+
geom_vline(xintercept = df[3,1],
color="#5034c4")+
theme_minimal() +
theme(text = element_text(color = "#795fc6"),
axis.text = element_text(color = "#795fc6"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.