首页 \ 问答 \ R - 在矩阵布局中组合十个图(R - combine ten plots in matrix layout)

R - 在矩阵布局中组合十个图(R - combine ten plots in matrix layout)

我试图使用矩阵布局组合十个图。 我几乎在那里,但我需要解决一个问题。 请看看我到目前为止的情况:

# Reproduce dataset
obs <- c(8.12903225806452, 4.65483870967742, 4.00967741935484, 2.82903225806452, 
1.02258064516129, 4.94838709677419, 2.03548387096774, 4.56129032258065, 
6.66451612903226, 10.4129032258065, 3.7741935483871, 9.93870967741936)

uncorrected <- structure(list(CanESM2 = c(3.71099209785461, 6.68828105926514, 
4.2675461769104, 4.29092979431152, 6.47999143600464, 6.30958032608032, 
3.28256869316101, 1.06898427009583, 4.01592206954956, 7.88787031173706, 
10.8663206100464, 9.14756298065186), GFDL.ESM2M = c(4.56643295288086, 
8.36136913299561, 4.6934700012207, 4.62750291824341, 6.34791326522827, 
0.916408598423004, 0.111764870584011, 0.570569038391113, 3.05491662025452, 
3.29908037185669, 5.98263263702393, 7.52161026000977), MRI.CGCM3 = c(3.94400858879089, 
2.48861312866211, 0.663281202316284, 0.422377318143845, 1.49548053741455, 
1.8869035243988, 5.35201597213745, 3.94722390174866, 5.0041446685791, 
6.11909627914429, 6.37435054779053, 5.9401068687439), NorESM1.M = c(8.83542060852051, 
8.36209106445312, 3.22844076156616, 2.86131143569946, 2.05858564376831, 
2.39689040184021, 1.06175291538239, 1.03921580314636, 2.49208211898804, 
6.83605766296387, 7.95251750946045, 4.8852391242981), inmcm4 = c(5.88600730895996, 
8.03514385223389, 3.86212635040283, 1.51728367805481, 3.46821308135986, 
1.30993270874023, 0.497318655252457, 0.589299857616425, 1.63358855247498, 
3.61927103996277, 4.99840354919434, 10.5596942901611)), .Names = c("CanESM2", 
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA, 
-12L))

corrected <- structure(list(CanESM2 = c(4.69295692443848, 6.2362003326416, 
4.48602199554443, 4.21368360519409, 6.02497625350952, 5.94498348236084, 
3.92529225349426, 1.07059073448181, 3.92306709289551, 8.00215721130371, 
10.9688482284546, 9.95723056793213), GFDL.ESM2M = c(6.74847173690796, 
10.7781000137329, 6.89084196090698, 7.5780816078186, 8.96726703643799, 
3.57111501693726, 1.20403492450714, 2.76221370697021, 4.98387718200684, 
5.27927255630493, 8.87845706939697, 9.95864582061768), MRI.CGCM3 = c(5.45173072814941, 
3.37272930145264, 2.20000958442688, 1.12101686000824, 2.67246603965759, 
3.10278224945068, 6.02392053604126, 4.70185708999634, 5.86025190353394, 
6.41299057006836, 7.1956262588501, 7.59840393066406), NorESM1.M = c(9.49540519714355, 
9.88559532165527, 4.86537599563599, 4.56189870834351, 3.85974431037903, 
4.07706260681152, 2.55634951591492, 2.63215637207031, 4.21092081069946, 
7.66422271728516, 8.75070095062256, 5.95497798919678), inmcm4 = c(8.21576976776123, 
11.1972188949585, 6.08181619644165, 3.58428621292114, 5.543297290802, 
3.46666693687439, 1.88991332054138, 1.94812619686127, 3.71879911422729, 
5.70409107208252, 6.85269260406494, 11.8774194717407)), .Names = c("CanESM2", 
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA, 
-12L))

# Create layout
m <- cbind(c(1,5,9), c(2,6,10), c(3,7,9), c(4,8,10))
layout(m)

# Plot
for (i in 1:length(names(uncorrected))) {
  # Plot uncorrected vs obs
  qqplot(as.vector(obs), uncorrected[,i], xlim=c(0,14), ylim=c(0,14),
         xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
         ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
  abline(0, 1)
  # Then plot corrected vs obs
  qqplot(as.vector(obs), corrected[,i], xlim=c(0,14), ylim=c(0,14),
         xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
         ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
  abline(0, 1)
}

这几乎就是我的需要。 但是,最后一个子图被拉伸到剩余矩阵行的长度。 相反,我想让最后一行中的两个图在中心对齐,与其他图的长度和宽度相同。

这可能吗?


I am trying to combine ten plots using a matrix layout. I am almost there, but there is a problem I need to fix. Please take a look at what I have so far:

# Reproduce dataset
obs <- c(8.12903225806452, 4.65483870967742, 4.00967741935484, 2.82903225806452, 
1.02258064516129, 4.94838709677419, 2.03548387096774, 4.56129032258065, 
6.66451612903226, 10.4129032258065, 3.7741935483871, 9.93870967741936)

uncorrected <- structure(list(CanESM2 = c(3.71099209785461, 6.68828105926514, 
4.2675461769104, 4.29092979431152, 6.47999143600464, 6.30958032608032, 
3.28256869316101, 1.06898427009583, 4.01592206954956, 7.88787031173706, 
10.8663206100464, 9.14756298065186), GFDL.ESM2M = c(4.56643295288086, 
8.36136913299561, 4.6934700012207, 4.62750291824341, 6.34791326522827, 
0.916408598423004, 0.111764870584011, 0.570569038391113, 3.05491662025452, 
3.29908037185669, 5.98263263702393, 7.52161026000977), MRI.CGCM3 = c(3.94400858879089, 
2.48861312866211, 0.663281202316284, 0.422377318143845, 1.49548053741455, 
1.8869035243988, 5.35201597213745, 3.94722390174866, 5.0041446685791, 
6.11909627914429, 6.37435054779053, 5.9401068687439), NorESM1.M = c(8.83542060852051, 
8.36209106445312, 3.22844076156616, 2.86131143569946, 2.05858564376831, 
2.39689040184021, 1.06175291538239, 1.03921580314636, 2.49208211898804, 
6.83605766296387, 7.95251750946045, 4.8852391242981), inmcm4 = c(5.88600730895996, 
8.03514385223389, 3.86212635040283, 1.51728367805481, 3.46821308135986, 
1.30993270874023, 0.497318655252457, 0.589299857616425, 1.63358855247498, 
3.61927103996277, 4.99840354919434, 10.5596942901611)), .Names = c("CanESM2", 
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA, 
-12L))

corrected <- structure(list(CanESM2 = c(4.69295692443848, 6.2362003326416, 
4.48602199554443, 4.21368360519409, 6.02497625350952, 5.94498348236084, 
3.92529225349426, 1.07059073448181, 3.92306709289551, 8.00215721130371, 
10.9688482284546, 9.95723056793213), GFDL.ESM2M = c(6.74847173690796, 
10.7781000137329, 6.89084196090698, 7.5780816078186, 8.96726703643799, 
3.57111501693726, 1.20403492450714, 2.76221370697021, 4.98387718200684, 
5.27927255630493, 8.87845706939697, 9.95864582061768), MRI.CGCM3 = c(5.45173072814941, 
3.37272930145264, 2.20000958442688, 1.12101686000824, 2.67246603965759, 
3.10278224945068, 6.02392053604126, 4.70185708999634, 5.86025190353394, 
6.41299057006836, 7.1956262588501, 7.59840393066406), NorESM1.M = c(9.49540519714355, 
9.88559532165527, 4.86537599563599, 4.56189870834351, 3.85974431037903, 
4.07706260681152, 2.55634951591492, 2.63215637207031, 4.21092081069946, 
7.66422271728516, 8.75070095062256, 5.95497798919678), inmcm4 = c(8.21576976776123, 
11.1972188949585, 6.08181619644165, 3.58428621292114, 5.543297290802, 
3.46666693687439, 1.88991332054138, 1.94812619686127, 3.71879911422729, 
5.70409107208252, 6.85269260406494, 11.8774194717407)), .Names = c("CanESM2", 
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA, 
-12L))

# Create layout
m <- cbind(c(1,5,9), c(2,6,10), c(3,7,9), c(4,8,10))
layout(m)

# Plot
for (i in 1:length(names(uncorrected))) {
  # Plot uncorrected vs obs
  qqplot(as.vector(obs), uncorrected[,i], xlim=c(0,14), ylim=c(0,14),
         xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
         ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
  abline(0, 1)
  # Then plot corrected vs obs
  qqplot(as.vector(obs), corrected[,i], xlim=c(0,14), ylim=c(0,14),
         xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
         ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
  abline(0, 1)
}

This is almost what I need. However, the last subplot is stretched to the length of the remaining matrix row. Instead, I'd like to have the two plots in the last row aligned in the center, in the same length and width as the others.

Is this possible?


原文:https://stackoverflow.com/questions/38689005
更新时间:2022-05-24 21:05

最满意答案

据我所知。 您可以为选项卡标题添加3个类别,并将每个列表框项目添加为子类别。 查询集合以查找标签标题的相关内容。

EX:

类别:1。食品2.书3.汽车子类别:1(食品):1。鸡蛋2.肉3.牛奶
等等..........


As per my understanding. You can put 3 category for tab headers and add the each list box items as sub category. query the collection for related of tab headers.

EX:

Category : 1. Food 2. Book 3. Car Sub Category: 1(Food): 1. Egg 2. Meat 3. Milk
etc..........

相关问答

更多
  • WPF的内置导航基础设施: WPF导航概述 另请查看向导示例 WPF has a navigation infrastructure built in: WPF Navigation Overview Also check out the wizard sample
  • 我最终决定如何做到这一点我自己。 我在这里发布答案,以便其他人可以看到一个可行的解决方案,也许一个WPF大师会来,并给我一个更好/更优雅的方式来做到这一点。 所以答案最终是#2。 揭示内部属性证明是正确的答案。 设置它实际上很容易..一旦你知道如何做到这一点。 没有很多完整的例子(我可以找到),所以希望这个会帮助遇到这个问题的别人。 ComboBoxWithLabel.xaml.cs 这个文件中重要的是使用DependencyProperties。 请注意,我们现在正在做的只是暴露属性(LabelConte ...
  • 我试图在互联网上找到一些这个问题的控制模板或解决方案,但是我没有找到任何“可接受的”解决方案。 所以我用这个方式写下来,这里是我第一次(和最后一次)的尝试的一个例子:
    您的代码尝试显示字典上名为name的属性,该属性不存在。 要访问索引器,请使用以下语法: listBox.DisplayMemberPath = "[name]"; 另外,你可能应该直接在XAML中设置这样的东西,而不是代码隐藏。 Your code tries to display a property called name on the dictionary, which doesn't exist. To access an indexer use the following syntax: li ...
  • 在新创建的UserControl ,您可以通过属性公开ListBox 。 然后,您可以通过UserControl访问ListBox 。 在UserControl.xaml.cs中的某个地方: public ListBox MyListBox { get { return {yourListBoxName}; } } 然后,当您实例化新的UserControl : ElementHost elhost = new ElementHost(); elhost.Size ...
  • 在这里阅读我的帖子,了解为什么会这样。 基本上,因为您在DataTemplate中连接View和ViewModel,所以每次收到焦点时,该选项卡都会重新创建视图。 是的,这会占用更多资源。 您可以通过以不同的方式连接视图和ViewModel来解决此问题(即Catelog方法,WAF或使用不同类型的项控件也可以做到这一点......) Here is a solution that creates a subclass of the TabControl. http://eric.burke.name/dot ...
  • 如果我理解你的问题,这样的事情应该有效。 首先:处理Rectangle上的Loaded事件: ... 这将为每个矩形调用rctProgSuccess_Loade ...
  • 创建以下样式并将Header属性绑定到ViewModel中的display属性 Create the following style and bind Header property to display property in ViewModel