ggplot2
連続スケールのプロットに個別のラベルを追加しようとしています。を使用してstat_function
(つまり、複数の関数をプロットすることについて)多くの質問があり、さまざまなスケールを使用する方法について多くの質問がありますが、この特定のインスタンスでスケールを変更する方法を理解するのに苦労しています。
プロットは次のとおりです。
myfun1 <- function(x) (13.076-96.543)*x + (-44.056 +102.057)*x^2 + (17.856 -42.996)*x^3 + (-2.996 + 7.444)*x^4 + (0.190 -0.450)*x^5 + 100.088 + 75.215 # average vs. lowest
myfun2 <- function(x) 13.076*x -44.056*x^2 + 17.856*x^3 -2.996*x^4 + 0.190*x^5 + 100.088 # lowest
myfun3 <- function(x) (13.076-183.093)*x + (-44.056 +229.447)*x^2 + (17.856 -99.353)*x^3 + (-2.996 + 17.517)*x^4 + (0.190 -1.080)*x^5 + 100.088 + 67.115 # highest vs. lowest
df <- data.frame(x = c(0, 6), y = c(0, 6))
myplot_weekday <- ggplot(data = df, aes(x = x, y = y)) +
stat_function(fun = myfun3, aes(color = "Highest")) +
stat_function(fun = myfun2, aes(color = "Lowest")) +
stat_function(fun = myfun1, aes(color = "Average")) +
theme_minimal() +
scale_colour_manual("Students' Course Grade", values = c("red", "black", "blue")) +
theme(legend.position = "top") +
theme(text=element_text(size= 14, family= "Times")) +
ylab("Minutes of Videos Watched") +
xlab("Weekday")
x軸(0、2、4、および6)の連続ラベルの代わりに、「日曜日」、「月曜日」、「火曜日」、「水曜日」、「木曜日」、「金曜日」を追加しようとしています。 、および「土曜日」ですが、私はこれに間違った方法でアプローチしているように感じます。
必要なブレーク(ラベルを取得)と対応するラベルを設定できます。
+ scale_x_continuous(breaks = 0:6,
labels = paste0(c("Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"), "day"))
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加