- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个要映射的数据框。 dfs 有相同的 xy 坐标,我需要一个 单色条带有可见的 离散色标对于两个 dfs,就像这里显示的一样。我希望颜色键中的颜色与自定义中断相匹配。非常感谢可以在此示例之外应用的更通用的解决方案
中的 RdYIBu 调色板RcolorBrewer 包是我所追求的。
到目前为止我的代码:
library(rasterVis)
ras1 <- raster(nrow=10,ncol=10)
set.seed(1)
ras1[] <- rchisq(df=10,n=10*10)
ras2=ras1*(-1)/2
s <- stack(ras1,ras2)
Uniques <- cellStats(s,stat=unique)
Uniques.max <- max(Uniques)
Uniques.min <- min(Uniques)
my.at <- round(seq(ceiling(Uniques.max), floor(Uniques.min), length.out= 10),0)
myColorkey <- list(at=my.at, labels=list(at=my.at))
levelplot(s, at=my.at, colorkey=myColorkey,par.settings=RdBuTheme())
最佳答案
以下应该让你继续前进。使用 ggplot2 文档和许多在线示例,您应该能够调整美学以使其看起来完全符合您的要求,而不会遇到任何麻烦。干杯。
#Order breaks from lowest to highest
my_at <- sort(my_at)
#Get desired core colours from brewer
cols0 <- brewer.pal(n=length(my_at), name="RdYlBu")
#Derive desired break/legend colours from gradient of selected brewer palette
cols1 <- colorRampPalette(cols0, space="rgb")(length(my_at))
#Convert raster to dataframe
df <- as.data.frame(s, xy=T)
names(df) <- c("x", "y", "Epoch1", "Epoch2")
#Melt n-band raster to long format
dfm <- melt(df, id.vars=c("x", "y"), variable.name="epoch", value.name="value")
#Construct continuous raster plot without legend
#Note usage of argument `values` in `scale_fill_gradientn` -
#-since your legend breaks are not equi-spaced!!!
#Also note usage of coord_equal()
a <- ggplot(data=dfm, aes(x=x, y=y)) + geom_raster(aes(fill=value)) + coord_equal()+
facet_wrap(facets=~epoch, ncol=1) + theme_bw() +
scale_x_continuous(expand=c(0,0))+
scale_y_continuous(expand=c(0,0))+
scale_fill_gradientn(colours=cols1,
values=rescale(my_at),
limits=range(dfm$value),
breaks=my_at) +
theme(legend.position="none", panel.grid=element_blank())
#Make dummy plot discrete legend whose colour breaks go along `cols1`
df_leg <- data.frame(x=1:length(my_at), y=length(my_at):1, value=my_at)
gg_leg <- ggplot(data=df_leg, aes(x=x, y=y)) + geom_raster(aes(fill=factor(value))) +
scale_fill_manual(breaks=my_at, values=cols1,
guide=guide_legend(title="",
label.position="bottom")) +
theme(legend.position="bottom")
#Extract discrete legend from dummy plot
tmp <- ggplot_gtable(ggplot_build(gg_leg))
leg <- which(sapply(tmp$grobs, function(x) x$name)=="guide-box")
legend <- tmp$grobs[[leg]]
#Combine continuous plot of your rasters with the discrete legend
grid.arrange(a, legend, ncol=1, heights=c(4, 0.8))
关于带有离散色标的光栅图,用于负值和正值 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33748871/
如何在 Flutter 中使 slider 离散看起来像上图? slider discrete 最佳答案 使用 divisions Slider 的属性(property)小部件将其分成相等的部分,然
我正在创建一个带有颜色条的散点图 plt.scatter(X, Y, c=Z) plt.colorbar() plt.show() plt.close() 其中 X 和 Y 是 float 组,Z 是
我刚刚在 android studio 中发现了 seekbar 离散小部件,我发现它非常有用,但我不知道如何删除步骤指示器,或者用更合适的可绘制对象更改它们。 有人设法做到了吗? 这是我当前搜索栏的
问题 请注意以下问题:巫师可以创建和销毁 rune 。创建一个新的 rune 需要消耗与先前创建的 rune 数量成比例的法力。摧毁 rune 会恢复创建 rune 所用的法力。下面,我提出一个可能的
我正在尝试使用 ggplot2 中的 sf 和 geom_sf 制作 map ,其中一组点数据使用连续颜色比例(-1 到 1),一组线数据使用离散比例(a、b、c、d)着色。但是,当我在同一张 map
我正在尝试在具有连续状态(dim.= 20)和离散操作(3 个可能的操作)的环境中找到最佳策略。并且有一个特定的时刻:对于最佳策略,一个操作(称为“操作 0”)的选择频率应比其他两个操作高得多(频率约
仅使用 x-y 位置移动绘制圆弧的最佳方法是什么?例如,假设我想在点 (4,4) 处绘制一个半径为 4 的圆。让我们看看我的“抽屉”从 (4,0) 开始,每个方向的分辨率为 0.1 步。我将如何创建一
我正在使用一个使用广义加法模型的随机站点级效应来拟合一个模型,该模型在 mgcv 中实现。 R 包。我一直在使用函数 gam() 执行此操作但是,为了加快速度,我需要转到 bam()框架,与gam()
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
是否可以同时使用 Intel HD 4000 集成显卡和独立 GPU,OpenCL(或 CUDA)作为设备,CPU 作为主机?我想要一些代码在集成显卡上运行,而其他代码同时在我的 GPU 上运行。 最
我是一名优秀的程序员,十分优秀!