一定期間の 2 つのグループ間で 3 つの異なる結果を比較するファセット折れ線グラフを作成しました。グループの 1 つでデータ ラベルを調整できるようにしたい (つまり、1 つのグループのラベルをデータ ポイントの上に表示し、2 番目のグループのラベルをデータ ポイントの下に表示する)。
これが私のコードです:
Year <- c("Y1", "Y2","Y3", "Y1", "Y2","Y3", "Y1", "Y2","Y3", "Y1", "Y2","Y3","Y1", "Y2","Y3",
"Y1","Y2","Y3")
Group <- c("Group A", "Group A", "Group A", "Group A", "Group A", "Group A", "Group A", "Group A", "Group A",
"Group B", "Group B", "Group B", "Group B","Group B", "Group B", "Group B", "Group B", "Group B" )
Test <- c("Test 1", "Test 1", "Test 1", "Test 2", "Test 2", "Test 2", "Test 3", "Test 3", "Test 3",
"Test 1", "Test 1", "Test 1","Test 2", "Test 2", "Test 2","Test 3", "Test 3", "Test 3")
Score <- c(68,70,73,61,62,65,61,62,65,
75,74,76,74,74,77,70,71,69)
df <- data.frame (Year, Group, Test, Score)
library(ggplot2)
ggplot (df, aes (x=Year, y=Score, group=Group)) + geom_line(aes(group=Group), size=1.5) + facet_grid(.~ Test)
ggplot(df, aes(x=Year, y=Score, colour=Group)) + geom_line(aes(group=Group), size=1.5) +
facet_grid(.~ Test) +
geom_point(size=4, shape=21) +
geom_text(aes(label = Score, vjust=-1))+
scale_y_continuous(limits = c(0,100), breaks=seq(0,100,20)) +
ylab("Percentage of Students") + xlab ("Year") +
labs(title = "Chart Title") +
theme(strip.text.x = element_text(size = 15, colour="black", angle = 0),
strip.background = element_rect(colour="white", fill="white")
)
どんな助けでも大歓迎です。