在折线图的 R 中更改 theme_pander 包中的图例名称和变量名称
Changing the legend name and variable name in the theme_pander package in R on a line graph
我一直在尝试将图表上的图例标题从“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")
)
我一直在尝试将图表上的图例标题从“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")
)