#r #ggplot2 #dummy-variable
Вопрос:
Мои данные таковы
black wage
1 0 769
2 0 808
3 0 825
4 0 650
5 0 562
6 1 1400
7 0 600
8 0 1081
9 0 1154
10 0 1000
мой код таков
b <- lm(wage~black, y)
ggplot(b, aes(black, wage))
geom_point()
stat_smooth(method = "lm", col = "red", se = F)
theme_minimal()
labs(x = '黑人', y = '薪水')
theme_minimal()
theme(text = element_text(family='黑體-繁 中黑'),
plot.title = element_text(size = rel(2.5), face = 'bold', hjust = 0.5),
axis.title = element_text(size = rel(1.5), face = 'bold'),
axis.text = element_text(size = rel(2), face = 'bold', colour = 'Black'),
panel.grid.minor.y = element_line(colour = NA))
график регрессии
https://i.stack.imgur.com/XO0nZ.png
Я хочу, чтобы на моей диаграмме были только 0 и 1 по оси x.
Ответ №1:
Автор: scale_x_continuous
,
ggplot(b, aes(black, wage))
geom_point()
stat_smooth(method = "lm", col = "red", se = F)
theme_minimal()
labs(x = '黑人', y = '薪水')
theme_minimal()
theme(text = element_text(family='黑體-繁 中黑'),
plot.title = element_text(size = rel(2.5), face = 'bold', hjust = 0.5),
axis.title = element_text(size = rel(1.5), face = 'bold'),
axis.text = element_text(size = rel(2), face = 'bold', colour = 'Black'),
panel.grid.minor.y = element_line(colour = NA))
scale_x_continuous(breaks = seq(0,1, by = 1),"黑人")