我正在使用ggtern以三级绘图的形式绘制一个大型数据集(参见下面的示例).
直到某个数据大小,一切都很完美,因为我使用的是geom_density_tern().因为我想要想象一个更加复杂的数据集加载所有它并且用ggplot渲染变得不可能(在内存方面的限制).我想也许可以通过计算单独计算的kde2d矩阵的结果来解决这个问题.那就是我被困住的地方.我想知道是否有可能在ggtern中做到这一点?
在任何情况下,我都添加了一个最小的数据结构和绘图,我现在使用它.
require(ggplot2)
require(ggtern)
set.seed(1)
mydata <- data.frame(
x = runif(100, min = 0.25, max = 0.5),
y = runif(100, min = 0.1, max = 0.4),
z = runif(100, min = 0.5, max = 0.7))
plot <- ggtern() +
theme_bw() +
theme_hidetitles() +
geom_density_tern(data = mydata,
aes(x = x, y = y, z = z, alpha = ..level.. ),
size = 0.1, linetype = "solid", fill = "blue")+
geom_point(data = mydata,
aes(x = x, y = y, z = …
Run Code Online (Sandbox Code Playgroud) 我试图想出一种使用R绘制三元热图的方法.我认为ggtern应该可以解决这个问题,但我不知道如何在vanilla ggplot2中执行像stat_bin这样的分箱功能.这是我到目前为止所拥有的:
require(ggplot2)
require(ggtern)
require(MASS)
require(scales)
palette <- c( "#FF9933", "#002C54", "#3375B2", "#CCDDEC", "#BFBFBF", "#000000")
sig <- matrix(c(1,2,3,4),2,2)
data <- data.frame(mvrnorm(n=10000, rep(2, 2), Sigma))
data$X1 <- data$X1/max(data$X1)
data$X2 <- data$X2/max(data$X2)
data$X1[which(data$X1<0)] <- runif(length(data$X1[which(data$X1<0)]))
data$X2[which(data$X2<0)] <- runif(length(data$X2[which(data$X2<0)]))
## Print 2d heatmap
ggplot(data, aes(x=X1, y=X2)) +
stat_bin2d(bins=50) +
scale_fill_gradient2(low=palette[4], mid=palette[3], high=palette[2]) +
xlab("Percentage x") +
ylab("Percentage y") +
scale_y_continuous(labels = percent) +
scale_x_continuous(labels = percent) +
theme_bw() + theme(text = element_text(size = 15))
data$X3 <- with(data, 1-X1-X2)
data <- data[data$X3 >= 0,] …
Run Code Online (Sandbox Code Playgroud) 我在R中使用ggtern绘制三元图,并希望在ggtern图上具有轴标签和断点,与原始数据相同。对于以下代码中生成的数据,每个轴的最大值为12、10和4。
在上一篇文章之后,我尝试使用中断和标签来执行此操作,但是每个轴仍在0-1比例尺上,缺少标签(由于它们超过1),并且带有标签的轴线不与点相交在情节上。(如何更改ggtern制作的三元图的标签?)
library(ggtern)
labFnc <- function(x,digits=2) format(round(unique(x),digits),digits=digits)
mydata <- data.frame(
x = runif(50, min = 0.25, max = 12),
y = runif(50, min = 0.1, max = 10),
z = runif(50, min = 0.5, max = 4),
value = runif(50, min = 10000, max = 20000))
ggtern(data = mydata,aes(x = x, y = y, z = z,col=value)) +
theme_bw() +
geom_point(alpha = 0.8, size = 3) +
theme_showarrows() +
scale_T_continuous(breaks=unique(mydata$x),labels=labFnc(mydata$x))+
scale_L_continuous(breaks=unique(mydata$y),labels=labFnc(mydata$y))+
scale_R_continuous(breaks=unique(mydata$z),labels=labFnc(mydata$z))
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?任何帮助将不胜感激。
编辑:我也尝试添加tern_limits参数。虽然这看起来会按比例扩大绘图,但数据放置在错误的位置。而且我无法像以前一样添加自己的独特休息时间。
ggtern(data = mydata,aes(x = …
Run Code Online (Sandbox Code Playgroud) 我有一个问题,它geom_hex_tern
与单个图完美配合,但是当我制作刻面时,十六进制 bin 的大小和形状会失真。
library(tidyverse)
library(ggtern)
# My data
dat <- structure(list(Fact2 = c(0.24, 0.24, 0.24, 0.24, 0.24, 0.24,
0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24,
0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24,
0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24,
0.24, 0.28, 0.28, 0.28, 0.28, 0.28), x = c(0.05, 0.1, 0.1, 0.1,
0.15, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.25, 0.25, 0.25, 0.25,
0.3, 0.3, 0.35, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试用 gganimate 为 R 中的三元图制作动画,而我面对着一堵墙。
library(tidyverse)
library(gganimate)
library(ggtern)
#> Registered S3 methods overwritten by 'ggtern':
#> method from
#> grid.draw.ggplot ggplot2
#> plot.ggplot ggplot2
#> print.ggplot ggplot2
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --
#>
#> Attaching package: 'ggtern'
#> The following objects are masked from 'package:ggplot2':
#>
#> aes, annotate, ggplot, ggplot_build, ggplot_gtable, ggplotGrob,
#> ggsave, layer_data, theme_bw, theme_classic, theme_dark,
#> theme_gray, theme_light, theme_linedraw, theme_minimal, theme_void
data=tibble(x=runif(200), y = runif(200), z …
Run Code Online (Sandbox Code Playgroud) 在下面的三元图中,轴外部的标签被剪掉。我找不到可以避免这种情况的ggtern()
设置ggplot2
。对于基本 R 图形,我只会使用xpd=TRUE
.
我的数据:
modes <-
structure(list(Mode = c("Literature", "Poetry", "Table", "Map",
"Thematic map", "Graph", "Art", "Diagram", "Statistical analysis",
"Statistical graphics"), Words = c(9L, 7L, 1L, 2L, 2L, 1L, 4L,
2L, 6L, 8L), Numbers = c(0.5, 1, 9, 2, 8, 1, 1, 0, 15, 8), Pictures = c(1L,
4L, 1L, 9L, 14L, 11L, 8L, 9L, 5L, 15L)), .Names = c("Mode", "Words",
"Numbers", "Pictures"), problems = structure(list(row = 10L,
col = NA_character_, expected = "4 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用库 ggtern 创建一个三元轮廓填充图。使用的代码是
a <- c(0.50, 0.625, 0.375, 0.25, 0.5625, 0.125, 0.25, 0.3125, 0.375, 0.4375, 0.1875, 0.3125, 0.375, 0.4375)
b <- c(0.25, 0.1875, 0.3125, 0.375, 0.25, 0.4375, 0.25, 0.375, 0.375, 0.4375, 0.875, 0.3125, 0.25, 0.125)
c <- c(0.25, 0.1875, 0.3125, 0.375, 0.1875, 0.4375, 0.50, 0.3125, 0.25, 0.125, 0.625, 0.375, 0.375, 0.4375)
d <- c(77.82325, 74.59318767, 76.76495015, 76.62122282, 77.95608657, 76.91320817, 68.50986659,8.53724416,80.32237597, 85.43315399, 61.80292426, 74.71471485, 73.27176908, 67.51782848)
df <- data.frame(a, b, c, d)
df$id <- 1:nrow(df)
#Build Plot
ggtern(data = df,aes(x = …
Run Code Online (Sandbox Code Playgroud) 我想在一个闪亮的应用程序中使用 的输出ggtern()
。然而,由于某些限制,它似乎失败了。
请参阅此处查看可重现的示例:
library(shiny)
library(ggtern)
ui <- fluidPage(
mainPanel(
plotOutput("ggtern")
)
)
server <- function(input, output) {
output$ggtern <- renderPlot({
ggtern(data.frame(x=10, y=30, z=60), aes(x, y, z)) + geom_point()
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
我是否忽略了什么?