私はここにいるのは初めてで、本当に助けていただければ幸いです!ggplot を使用して対数変換されたデータをプロットし、95% の信頼区間と予測区間をプロットする単純な r スクリプトがあります。ただし、軸をフォーマットする方法にこだわっています...対数スケールにしたいです。私はチュートリアルからこれを学び、スクリプトを実行してから軸を変換しようとしましたが、信頼区間が台無しになります。
私は使用してみました:
scale_y_continuous(trans=log2_trans())+
scale_x_continuous(trans=log2_trans())
しかし、それは95%の信頼区間を変換しません...どんな提案もいただければ幸いです! 基本的に、私は、すでに素晴らしいグラフで見栄えのする対数スケールを取得する簡単な方法を探しています。
これが私のコードです(参照用にすべてのデータを少しだけ含めたわけではありません):
x <- c(6135.0613509,945.2650501,1927.8260200,110.0000000,
3812.9674276,3.2991626,1173.4923354,945.2650501,
114.2114798,11.2463797)
y <- c(370.00,32.00,2900.00,52.00,1500.00,0.06,16.00,50.00,5.00,11.00)
df <- data.frame(x, y)
# Log transformation
log_x <- log(x)
log_y <- log(y)
# Plot
plot(log_x,log_y)
# Linear Regression - linear model function
model1 <- lm(log_y ~ log_x, data = df)
summary(model1)
abline(model1, col = "lightblue") # Add trendline to plot of log transformed
data
# load ggplot2
library(ggplot2)
# Confidence and Prediction intervals
temp_var <- predict(model1, interval = "prediction")
## Warning in predict.lm(model1, interval = "prediction"): predictions on
## current data refer to _future_ responses
new_df <- cbind(df, temp_var)
ggplot(new_df, aes(log_x, log_y))+
geom_point() +
geom_line(aes(y = lwr), color = "red", linetype = "dashed")+
geom_line(aes(y = upr), color = "red", linetype = "dashed")+
geom_smooth(method = lm, se = TRUE)