我一直试图将图表上的图例标题从"Political_Party"更改为"政党",将变量从"D"和"R"更改为"民主党"和"共和党",但在我制作的图表中无济于事。下面重现了我用于图形的代码。
Raw_Plot_Cases <-
ggplot(Combined_Averages_Cases, aes(x = date, y = CasesperDay, group = Political_Party, color = Political_Party)) +
geom_line()
Raw_Plot_Cases <- Raw_Plot_Cases +
theme_pander() +
scale_x_date(date_breaks = "1 month", labels = date_format("%b %d")) +
scale_color_manual(values=c('#0015BC','#DE0100')) +
theme(plot.title.position = "plot",
plot.caption = element_markdown(),
legend.position = "bottom",
axis.title.x = element_text(),
legend.title = element_text("Political Party")) +
labs(title = "Average State-Wide Daily Covid-19 Cases",
subtitle = "By Political Party",
x = "Date",
y = "Daily Cases",
caption = "Data from *The New York Times*, based on reports from state and local health agencies.")
主题决定了事物(如图例标题(的格式 - 它不定义文本。你的传奇看起来是一个color
传奇。设置颜色图例名称标签的两个不错的选择是 (a( 在labs()
呼叫中添加color = "Political Party"
,在其中设置所有其他文本,或 (b( 将name = "Political Party"
放入scale_color_manual()
呼叫中。
同样,要将D
更改为Democrat
,将R
更改为Republican
,有两个不错的选择。一种是更改实际数据中的值,另一种是在scale_color_manual
中设置标签,如下所示:
scale_color_manual(
values = c('#0015BC','#DE0100'),
breaks = c("D", "R"),
labels = c("Democrat", "Republican")
)