我似乎找不到一種方法來組合兩個具有不同功能范圍的 ggplots。
library(ggplot2)
myfun <- function(x) {
1/(1 exp(-x))}
ggplot( NULL,aes(x))
stat_function(data=data.frame(x=c(0, 20)),fun=myfun, geom="line")
stat_function(data=data.frame(x=c(10, 20)),fun=1/myfun, geom="line")

編輯:問題中有一個錯誤:1/myfunc而不是myfunc在第二個函式資料中。
uj5u.com熱心網友回復:
我不確定這是否是您想要的,但我根據兩個范圍為您的函式提供兩種不同的顏色。您可以使用以下代碼:
library(ggplot2)
myfun <- function(x) {
1/(1 exp(-x))}
ggplot(NULL)
stat_function(data= data.frame(x = c(0, 10)), aes(x, color = "blue"), fun=myfun, xlim = c(0,10))
stat_function(data= data.frame(x = c(10, 20)), aes(x, color = "red"), fun=myfun, xlim = c(10,20))
scale_color_manual(labels = c("blue", "red"), values = c("blue", "red"))
輸出:

正如您在圖中看到的,該函式繪制在兩個不同的范圍內。
回答已編輯的問題
我建議只做這樣的第二個功能:
library(ggplot2)
myfun1 <- function(x) {
1/(1 exp(-x))}
myfun2 <- function(x) {
1/(1/(1 exp(-x)))}
ggplot( NULL)
stat_function(data=data.frame(x=c(0, 20)),fun=myfun1, geom="line")
stat_function(data=data.frame(x=c(10, 20)),fun=myfun2, geom="line")
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/454429.html
上一篇:將重復的行轉換為一行,其中一些值折疊成由字符分隔的單列
下一篇:將串列的一列轉換為R中的虛擬
