需要“ggtern”三元图网格线和轴刻度

jdzmm42g  于 2023-03-15  发布在  其他
关注(0)|答案(2)|浏览(123)

我正在尝试在三元图中添加网格线和坐标轴刻度。我可以调整坐标轴的数值,但无法在图中获取坐标轴刻度和网格。
下面是一个R代码示例:

library(ggplot2)
# Example data
x <- rnorm(100)
y <- rnorm(100)
z<-rnorm(100)
df <- data.frame(x, y, z)

# Create scatter plot with grid lines
ggtern(df, aes(x, y, z)) +
  geom_point() +
  theme_showgrid()+
  theme(panel.grid.major = element_line(color = "grey", linetype = "dashed"),
  panel.grid.minor = element_line(color = "grey", linetype = "dashed"))

我来拿这个

我要这个

3npbholx

3npbholx1#

您可以使用ggplot2的旧版本3.3.5,并按如下方式使用theme_bw

library(remotes)
install_version("ggplot2", version = "3.3.5", repos = "http://cran.us.r-project.org")
#> Downloading package from url: http://cran.us.r-project.org/src/contrib/Archive/ggplot2/ggplot2_3.3.5.tar.gz
library(ggplot2)
library(ggtern)

# Example data
x <- rnorm(100)
y <- rnorm(100)
z<-rnorm(100)
df <- data.frame(x, y, z)

# Create scatter plot with grid lines
ggtern(df, aes(x, y, z)) +
  geom_point() +
  theme_bw()

创建于2023年3月11日,使用reprex v2.0.2

bmvo0sr5

bmvo0sr52#

这个剧本成功了

library(remotes)

install_version("ggplot2", version = "3.3.5", repos = "http://cran.us.r-project.org")
#> Downloading package from url: http://cran.us.r-project.org/src/contrib/Archive/ggplot2/ggplot2_3.3.5.tar.gz
library(ggplot2)

install_version("ggtern", version = "3.3.5", repos = "http://cran.us.r-project.org")
library(ggtern)

# Example data
x <- rnorm(100)
y <- rnorm(100)
z<-rnorm(100)
df <- data.frame(x, y, z)

# Create scatter plot with grid lines
ggtern(df, aes(x, y, z)) +
  geom_point() +
  theme_bw()+theme_showgrid()

相关问题