r - if 条件 R 内的多个图
问题描述
我正在使用一个if
条件来处理一些数据并创建三个不同的图表,这些图表显示在Viewer
if (S2_input){
S2_images<-stack(S2_rsp)
S2_images
cubeView(S2_images)
# Plot True/False color
viewRGB(S2_images, 3,2,1, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik"))
viewRGB(S2_images, 4,3,2, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik"))
}
哪里S2_images
是:
> S2_images
class : RasterStack
dimensions : 660, 1074, 708840, 30 (nrow, ncol, ncell, nlayers)
resolution : 10, 10 (x, y)
extent : 219800, 230540, 4097480, 4104080 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
names : L2A_T30ST//51_B02_10m, L2A_T30ST//51_B03_10m, L2A_T30ST//51_B04_10m, L2A_T30ST//51_B08_10m, L2A_T30ST//51_B11_20m, L2A_T30ST//51_B12_20m, L2A_T30ST//21_B02_10m, L2A_T30ST//21_B03_10m, L2A_T30ST//21_B04_10m, L2A_T30ST//21_B08_10m, L2A_T30ST//21_B11_20m, L2A_T30ST//21_B12_20m, L2A_T30ST//51_B02_10m, L2A_T30ST//51_B03_10m, L2A_T30ST//51_B04_10m, ...
min values : 1, 127, 6, 1, 88, 86, 1, 1, 1, 1, 1, 1, 50, 198, 7, ...
max values : 8702, 9090, 7589, 7322, 5379, 5474, 8743, 9298, 7585, 8530, 5712, 5905, 8048, 7692, 7187, ...
问题来了,当我运行完整的if
语句时,查看器中只显示最终语句viewRGB
。知道如何在条件内创建所有这些吗?
解决方案
正如您在此处看到的在 R 中打印 'Hello world' n 次,R 仅显示循环内的最后一条指令,因此解决您的问题的方法是将您的地图包装在一个print()
so 中:
if (S2_input){
S2_images<-stack(S2_rsp)
S2_images
cubeView(S2_images)
# Plot True/False color
print(viewRGB(S2_images, 3,2,1, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik")))
viewRGB(S2_images, 4,3,2, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik"))
}
或者
if (S2_input){
S2_images<-stack(S2_rsp)
S2_images
cubeView(S2_images)
# Plot True/False color
print(viewRGB(S2_images, 3,2,1, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik")))
print(viewRGB(S2_images, 4,3,2, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik")))
}
或者,您还可以构建地图向量:
if (S2_input){
S2_images<-stack(S2_rsp)
S2_images
cubeView(S2_images)
# Plot True/False color
v <-c(viewRGB(S2_images, 3,2,1, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik")),viewRGB(S2_images, 4,3,2, map.types=c("Esri.WorldTopoMap", "Esri.WorldImagery", "OpenStreetMap.Mapnik")))
v
}
推荐阅读
- mongodb - Firebase 函数偶尔无法完成执行
- javascript - 如何在javascript中从HTML列表中保存多个文本对象
- python-2.7 - 如何在 QTableView (PyQt4) 中选择多个单元格?
- r - 点(“.”)和波浪号(“~”)在 R 中代表什么?
- java - API Rest Java EE 错误:必须是公共范围的,否则该方法将被忽略 e EntityManager 没有持久性
- java - Arduino 到 Java 的通信
- r - 删除我单击的点后,我试图重新生成散点图
- ruby-on-rails - 如何在终端中使用单个命令在 RSpec 中运行多个规范文件?
- excel - 整个 uft 程序正在执行结果集中不应该获取的记录数
- google-cloud-storage - 谷歌存储:我可以创建一个存储桶,但我无法访问“转移”功能