Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GG是笛卡尔的。如何改变边际规模?_R_Ggplot2 - Fatal编程技术网

R GG是笛卡尔的。如何改变边际规模?

R GG是笛卡尔的。如何改变边际规模?,r,ggplot2,R,Ggplot2,我试图用ggplot绘制一个2D密度图,并添加边缘直方图。问题是多边形渲染很愚蠢,需要提供额外的填充以渲染轴限制以外的值(例如,在本例中,我将限制设置为0到1之间,因为该范围以外的值没有物理意义)。我仍然想要密度估计,因为它通常比块状的2D热图干净得多 除了完全取消GGM并花费另外50行代码尝试对齐直方图之外,还有什么办法可以解决这个问题吗 难看的线条: 现在渲染工作正常,但GGM忽略了选择笛卡尔(),这会破坏绘图: 数据如下: dataset您可以通过使用xlim()和ylim()而不是

我试图用ggplot绘制一个2D密度图,并添加边缘直方图。问题是多边形渲染很愚蠢,需要提供额外的填充以渲染轴限制以外的值(例如,在本例中,我将限制设置为0到1之间,因为该范围以外的值没有物理意义)。我仍然想要密度估计,因为它通常比块状的2D热图干净得多

除了完全取消GGM并花费另外50行代码尝试对齐直方图之外,还有什么办法可以解决这个问题吗

难看的线条:

现在渲染工作正常,但GGM忽略了
选择笛卡尔()
,这会破坏绘图:

数据如下:


dataset您可以通过使用
xlim()
ylim()
而不是
coord\u cartesian
来解决此问题

dataset <- read.csv("~/Desktop/dataset.csv")

library(ggplot2)
library(ggthemes)
library(ggExtra)

plot_center <- ggplot(data = dataset, aes(x = E,
                                          y = S)) +
    stat_density2d(aes(fill=..level..),
                   bins= 8, 
                   geom="polygon",
                   col = "black",
                   alpha = 0.5) + 
    scale_fill_continuous(low = "yellow",
                          high = "red") +
    scale_x_continuous(limits = c(-1,2)) + # Render padding for polygon
    scale_y_continuous(limits = c(-1,2)) + #
    xlim(c(0,1)) +
    ylim(c(0,1)) +
    theme_tufte(base_size = 15, base_family = "Roboto") +
    theme(axis.text    = element_text(color = "black"),
          panel.border = element_rect(colour = "black", fill=NA, size=1),
          legend.text  = element_text(size = 12, family = "Roboto"),
          legend.title = element_blank(),
          legend.position = "none")

ggMarginal(plot_center,
           type = "histogram",
           col = "black",
           fill = "orange",
           margins = "both")

dataset您可以通过使用
xlim()
ylim()
而不是
coord\u cartesian
来解决此问题

dataset <- read.csv("~/Desktop/dataset.csv")

library(ggplot2)
library(ggthemes)
library(ggExtra)

plot_center <- ggplot(data = dataset, aes(x = E,
                                          y = S)) +
    stat_density2d(aes(fill=..level..),
                   bins= 8, 
                   geom="polygon",
                   col = "black",
                   alpha = 0.5) + 
    scale_fill_continuous(low = "yellow",
                          high = "red") +
    scale_x_continuous(limits = c(-1,2)) + # Render padding for polygon
    scale_y_continuous(limits = c(-1,2)) + #
    xlim(c(0,1)) +
    ylim(c(0,1)) +
    theme_tufte(base_size = 15, base_family = "Roboto") +
    theme(axis.text    = element_text(color = "black"),
          panel.border = element_rect(colour = "black", fill=NA, size=1),
          legend.text  = element_text(size = 12, family = "Roboto"),
          legend.title = element_blank(),
          legend.position = "none")

ggMarginal(plot_center,
           type = "histogram",
           col = "black",
           fill = "orange",
           margins = "both")
数据集