- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 ggplot 中的现有直方图上绘制第二个变量,但我不确定如何实现这一点或这叫什么。基本上,类似于添加密度线,但使用来自另一列的数据(与直方图使用的变量不同)。这是一个例子:
我的数据(出于隐私目的并保持代码简短,仅占我实际数据的 3%):
structure(list(mm = c(88L, 57L, 260L, 100L, 401L, 67L, 146L, 162L, 406L, 60L, 150L, 237L, 154L, 425L, 142L, 65L, 180L, 35L, 147L, 50L, 126L, 32L, 45L, 403L, 144L, 170L, 288L, 150L, 249L, 146L, 174L, 433L, 126L, 85L, 136L, 55L, 132L, 132L, 97L, 388L, 120L, 130L, 210L, 121L, 597L, 453L, 40L, 101L, 80L, 196L, 215L, 224L, 185L, 164L, 39L, 195L, 249L, 165L, 209L, 49L, 510L, 143L, 180L, 131L, 390L, 96L, 436L, 166L, 69L, 162L, 64L, 111L, 119L, 131L, 213L, 64L, 54L, 178L, 48L, 57L, 265L, 132L, 485L, 147L, 103L, 70L, 60L, 284L, 157L, 112L, 256L, 187L, 141L, 151L, 215L, 78L, 375L, 107L, 94L, 235L, 94L, 369L, 118L, 143L, 249L, 448L, 127L, 121L, 383L, 119L, 100L, 162L, 45L, 69L, 187L, 64L, 156L, 204L, 140L, 280L, 120L, 261L, 229L, 122L, 185L, 175L, 130L, 141L, 82L, 58L, 106L, 115L, 151L, 94L, 112L, 60L, 400L, 122L, 113L, 110L, 114L, 148L, 303L, 376L, 406L, 301L, 129L, 122L, 495L, 90L, 152L), YP = c("YP", "other", "YP", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "other", "YP", "YP", "other", "other", "YP", "other", "YP", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "YP", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "YP", "other", "other", "YP", "YP", "other", "other", "other", "other", "other", "YP", "other", "other", "other", "other", "YP", "other", "other", "other", "other", "YP", "other", "other", "YP", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "other", "YP", "other", "other", "other", "other", "YP", "other", "YP", "YP", "YP", "other", "other", "other", "other", "other", "YP", "YP", "other", "other", "other", "YP", "YP", "other", "other", "other", "other", "YP", "YP", "YP", "other", "YP", "other", "other", "YP", "other", "YP", "other", "other", "other"), TS = c(72.2364762348789, 56.072368188802,
112.558570306398, 76.9944343224768, 128.685244324351, 62.0886592937318,
91.0798384599843, 94.9503355973493, 129.146464600376, 57.9815046059066,
92.0858456462626, 109.11119845305, 93.0653758618353, 130.848758867367,
90.0458830839189, 60.9606941855156, 98.8718539901336, 37.920054848636,
91.3339008799045, 51.1954962620356, 85.596412576734, 34.5846903022058,
47.2739778692513, 128.870418835656, 90.5664510102187, 96.7444178270107,
116.36538907066, 92.0858456462626, 110.949596806416, 91.0798384599843,
97.6100382367648, 131.542858236253, 85.596412576734, 70.9454797665696,
88.4390148470959, 54.7429411543526, 87.3278875586647, 87.3278875586647,
75.8607426198959, 127.458618740778, 83.7804426663477, 86.7596322459568,
104.609342293304, 84.0893241071107, 143.497154960473, 133.223504910479,
42.8900932821207, 77.3647856368317, 68.6890313425619, 102.04142761656,
105.485147406912, 107.011466050045, 99.8916438094152, 95.4070284436167,
41.9477644689454, 101.851043569743, 110.949596806416, 95.6332905385796,
104.43168085813, 50.4435514956775, 137.634767211238, 90.3070771382737,
98.8718539901336, 87.0448443695468, 127.649981630184, 75.4750396864329,
131.799844297451, 95.8581854826305, 63.18344410111, 94.9503355973493,
60.383628362647, 80.8787140928451, 83.4689764136111, 87.0448443695468,
105.137294407705, 60.383628362647, 54.0599862131223, 98.4559837418714,
49.6761016259917, 56.072368188802, 113.267544123207, 87.3278875586647,
135.764021720693, 91.3339008799045, 78.0946129419071, 63.7189929090771,
57.9815046059066, 115.84482114436, 93.783468875064, 81.2125279896034,
111.981504483529, 100.291862719328, 89.7828431198754, 92.3331555262515,
105.485147406912, 67.7467025293866, 126.190186686619, 79.5126892186721,
74.6914317960895, 108.795772836446, 74.6914317960895, 125.589851091188,
83.1548817226121, 90.3070771382737, 110.949596806416, 132.810404110486,
85.8906433579888, 84.0893241071107, 126.975862297304, 83.4689764136111,
76.9944343224768, 94.9503355973493, 47.2739778692513, 63.18344410111,
100.291862719328, 60.383628362647, 93.5456405898278, 103.530426170882,
89.5179309695183, 115.316869029959, 83.7804426663477, 112.701449560551,
107.833132972289, 84.3956632849718, 99.8916438094152, 97.8233339494332,
86.7596322459568, 89.7828431198754, 69.6080903831755, 56.7196888525377,
79.1632030828511, 82.1963738176802, 92.3331555262515, 74.6914317960895,
81.2125279896034, 57.9815046059066, 128.592310443359, 84.3956632849718,
81.5433746124733, 80.5418792147937, 81.8713062492431, 91.5862408295004,
118.255135021059, 126.289307916972, 129.146464600376, 118.008644053953,
86.4722176903414, 84.3956632849718, 136.523639922807, 73.0729159296925,
92.5788329858984)), class = "data.frame", row.names = c(NA, -151L ))
我拥有的直方图,我想在其顶部绘制“TS”,类似于添加密度曲线,我猜但有第二个变量(带有我的整个数据的实际直方图看起来更好,只是一个例子):
ggplot(DATA, aes(x=mm, color = YP, fill = YP)) +
geom_histogram(bins = 80, position="identity") +
scale_x_continuous(name = "TL (mm)", breaks = seq(0, 800, 50)) +
scale_y_continuous(name = "Count", breaks = seq(0,290, 10)) +
scale_fill_manual(name = "Species",
labels = c("Other", "SP of interest"),
values = c("gray48", "gray9")) +
scale_color_manual(name = "Species",
labels = c("Other", "SP of interest"),
values = c("gray48", "gray9")) +
ggtitle("MY PLOT") +
theme_clean() +
theme(plot.title = element_text(hjust = 0.5), legend.position = c(0.7, 0.7))
如何在此直方图顶部添加“TS”变量(类似于密度曲线,但使用 TS 变量)?我的目标是以这样的方式结束:
我尝试了以下方法,但当我想要曲线时,它只是在顶部绘制另一个直方图:
ggplot(DATA) +
geom_histogram(aes(x=mm)) +
geom_histogram(aes(x=TS), fill = 'black') +
scale_x_continuous(name = "TL (mm)", breaks = seq(0, 700, 50)) +
scale_y_continuous(name = "Count", breaks = seq(0,50, 10)) +
ggtitle("MY PLOT") +
theme_clean() +
theme(plot.title = element_text(hjust = 0.5), legend.position = c(0.7, 0.7))
我尝试用 geom_密度做类似的事情,但没有发生太多事情:
ggplot(DATA) +
geom_histogram(aes(x=mm)) +
geom_density(aes(x=TS), fill = 'black', color='black', alpha = 0.25) +
scale_x_continuous(name = "TL (mm)", breaks = seq(0, 700, 50)) +
scale_y_continuous(name = "Count", breaks = seq(0,50, 10)) +
ggtitle("MY PLOT") +
theme_clean() +
theme(plot.title = element_text(hjust = 0.5), legend.position = c(0.7, 0.7))
也许是这样的,但将其绘制在我的直方图之上......
ggplot(DATA) +
geom_density(aes(x=TS), fill = 'black', color='black', alpha = 0.25) +
scale_x_continuous(name = "TL (mm)", breaks = seq(0, 700, 50)) +
scale_y_continuous(name = "Count", breaks = seq(0,50, 10)) +
ggtitle("MY PLOT") +
theme_clean() +
theme(plot.title = element_text(hjust = 0.5), legend.position = c(0.7, 0.7))
我还没有在网上找到能够实现我想要的效果的示例。谢谢!
最佳答案
您可以使用geom_密度
,但将密度乘以足够大的值以查看,并使用辅助轴来准确读取密度。为了使其发挥作用,您需要将密度缩放到与直方图类似的比例(您的样本数据乘以 800 大约是正确的)。
在 scale_y_continuous
调用中,添加一个用于反转转换的 sec.axis
:
ggplot(DATA, aes(x=mm, color = YP, fill = YP)) +
geom_histogram(bins = 80, position="identity") +
scale_x_continuous(name = "TL (mm)", breaks = seq(0, 800, 50)) +
scale_fill_manual(name = "Species",
labels = c("Other", "SP of interest"),
values = c("gray48", "gray9")) +
scale_color_manual(name = "Species",
labels = c("Other", "SP of interest"),
values = c("gray48", "gray9")) +
ggtitle("MY PLOT") +
ggthemes::theme_clean() +
theme(plot.title = element_text(hjust = 0.5), legend.position = c(0.7, 0.7)) +
geom_density(aes(y = ..density.. * 800), fill = "black", colour = "black",
position = "identity", alpha = 0.3) +
scale_y_continuous(name = "Count", breaks = seq(0,290, 10),
sec.axis = sec_axis(~.x/800, name = "TS density"))
关于r - 如何将第二个变量添加到直方图 ggplot 并在顶部当前直方图上绘图,从第二个变量添加密度曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72071765/
我正在尝试编写一个函数来制作绘图并将其自动保存到文件中。 我努力用它来动态地做的技巧[plotname=varname & filename=varname &], 并使其与从循环中调用它兼容。 #
有人可以帮助我如何在绘图条形图中添加“下拉”菜单。 我在以下链接 ( https://plot.ly/python/v3/dropdowns/ ) 上找到了一些信息,但我正在努力调整代码,因此下拉选项
我不确切知道如何表达这一点,但我本质上希望根据其他数据之前的列值将数据分组为 Excel 图的系列。例如: size weight apple 3 35 orange 4
我正在为出版物创建图表并希望它们具有相同的字体大小。 当我用多图创建图形时,字体大小会减小,即使我没有更改tiff() 分辨率或pointsize 参数。我根据最终适合的地 block 数量增加了图形
我用 glm::perspective(80.0f, 4.0f/3.0f, 1.0f, 120.0f);并乘以 glm::mat4 view = glm::lookAt( glm::vec3(
我在 Shiny UI 中有一个情节。如果我更改任何输入参数并且通过 react 性图将会改变。但是让我们考虑以下情况:- Shiny UI 中的绘图可以说股票的日内价格变动。为此,您查询一些实时数据
我对 R 有点陌生。我在以下两个线程中跟踪并实现了结果: http://tolstoy.newcastle.edu.au/R/e17/help/12/03/7984.html http://lukem
我想在 WPF 控件中使用 GDI+ 绘图。 最佳答案 有多种方法可以做到这一点,最简单的方法是锁定您使用 GDI 操作的位图,获取像素缓冲区(从锁定中获取的 BitmapData 中的 Scan0
如何在以下取自其网站的绘图示例中隐藏颜色条? df % layout(title = '2014 Global GDPSource:CIA World Factbook',
我有两列数据,X 和 Y,每个条目在两个向量的小数点后都有 4 位数据。 当我使用 plot(x,y) 绘制简单图时,轴上显示的数据精确到小数点后两位。如何在两个轴上将其更改为小数点后 4 位精度?
我目前正在使用 Canvas 处理 JavaFX-Drawing-Application。在 GraphicsContext 的帮助下,我使用 beginPath() 和 lineTo() 方法绘制线
如果这个问题已经得到解答,但我无法找到我需要的东西,我提前道歉。我想从名为 data1.dat、data2.dat 的文件中绘制一些结果......我设法通过循环导入数据,但我无法使用循环绘制结果。仅
我的 pandas 数据框中有一个功能,可以(可能)具有多个级别。我可以使用以下方法获得独特的级别: reasons = df["Reason"].unique() 我可以通过执行以下操作在单个图表上
我在 Ubuntu 14 和 Windows 7(均为 64 位)中用 Python 绘制结果时遇到问题。作为一个简单的比较,我做了: from tvb.simulator.lab import *
以下代码相当简单 - 它用随机选择的像素填充设计表面 - 没什么特别的(暂时忽略第二种方法中的 XXXXXXX)。 private void PaintBackground() { Rando
我正在尝试制作一个绘制函数图形的 swing 应用程序(现在很简单,例如 x+2)但我在根据屏幕坐标制作我的点的数学坐标时遇到问题。我希望它在我的图表中简单地画一条从 P1(0,1) 到 P2(1,2
编辑 4:问题的新格式 背景:我有一个扩展 JFrame 的类 Window,在 JFrame 中我有一个 Canvas 。我向 Canvas 添加自定义对象。这个对象的唯一目的(为了争论)是在 Ca
我需要为即将到来的锦标赛标记阶梯,但我找不到任何方法来语义标记它。到目前为止我看到的唯一方法是 mark it up as a table ,我想不惜一切代价避免这种情况。 有什么想法吗? 最佳答案
我目前正在为一个小型 uC 项目编写 UI。在计算垂直线的位置时遇到一些问题。这个想法是将红线沿 x 轴移动到矩形的末端。 使用无限旋转编码器递增的值,范围为 0 到 800,增量为 1。矩形的左侧是
我正在尝试绘制光分布图。我想准确地执行此问题的第一步所要求的:Statistical analysis on Bell shaped (Gaussian) curve . 现在我有一组值。我希望数组元
我是一名优秀的程序员,十分优秀!