data.frame(
bill = c(1L,1L,2L,2L,3L,3L,4L,4L,5L,5L,
6L,6L,7L,7L,8L,8L,9L,9L,10L,10L,11L,11L,12L,12L),
treat = c(0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,
0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L),
monthenergy = c(36.7032538284079,46.0402438841829,
32.9392795881018,41.2984949950169,28.1280279158878,
35.480098154243,24.9235110867169,31.8601494904683,25.8690610384381,
33.4558628130817,29.2486150406169,38.301071827994,
37.3012423685873,49.7570793648139,37.1106026686834,49.1615012450902,
38.0010307369504,50.4640419568872,25.6031441545062,
33.6860808231507,25.4171150782655,32.6026074847544,31.1551553278784,
39.2106574963103)
)
I need to draw a figure such that the x-axis is "bill" (12 months), y-axis is "monthenergy". And this figure should have 2 lines (treatment and control group). My codes are:
# draw the figure
x_min <- min(month_mean$bill)
x_max <- max(month_mean$bill)
month_mean %>% ggplot(aes(y=monthenergy, x=bill, color=factor(treat))) +
geom_point() +
geom_line() +
theme_minimal() +
theme(plot.title = element_text(face = "bold", size = 14, hjust = 0.5),
plot.subtitle = element_text(size = 12, hjust = 0.5)) +
labs(title = "Participants' and Nonparticipants' Average Energy Use in 2011",
x="Month", y="Energy Use", color="Group") +
scale_color_discrete(name="Group",
breaks=c("0","1"),
labels=c("Control","Treatment")) +
scale_y_continuous(label=percent) +
scale_x_date(labels = date_format("%h-%y"),
breaks = seq(from = x_min,
to = x_max,
by = "2 bill"))
I believe my codes contain more than 1 error.