R MATLAB绘图函数类似于Lattice软件包中的xyplot()
我想知道是否有类似于R中lattice包中的R MATLAB绘图函数类似于Lattice软件包中的xyplot(),r,matlab,scatter-plot,R,Matlab,Scatter Plot,我想知道是否有类似于R中lattice包中的xyplot()函数的函数。我想在不同的图表中绘制按子组分类的观察组 例如,如果我有以下数据帧: d <- data.frame(ID=paste0("id",1:40), Group=paste0("group",rep(1:4,10)), Subgroup=paste0("subgroup",c(rep(c("A","B","B"),13),"A")), ValueX=rnorm(40),
xyplot()
函数的函数。我想在不同的图表中绘制按子组分类的观察组
例如,如果我有以下数据帧:
d <- data.frame(ID=paste0("id",1:40),
Group=paste0("group",rep(1:4,10)),
Subgroup=paste0("subgroup",c(rep(c("A","B","B"),13),"A")),
ValueX=rnorm(40),
ValueY=rnorm(40))
在MATLAB中,我将d
定义为一个数据集,并使用sbiotrellis
函数绘制以下内容:
sbiotrellis(d,'Group','ValueX','ValueY')
但是,这些小组没有得到考虑。有什么想法吗?R:
write.table(d, file = "myfile.csv", sep = ",", row.names = FALSE)
Matlab:
write.table(d, file = "myfile.csv", sep = ",", row.names = FALSE)
操作系统
lsb_release -i -r
Distributor ID: RedHatEnterpriseServer
Release: 6.5
Matlab版本与发布
version -date
% ans =
%
% September 15, 2014
version -release
% ans =
%
% 2014b
version -java
%ans =
%
%Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
资料
根据子组变量将数据分组
target = 'subgroupA';
vi = find(cellfun('length', regexp(ds.Subgroup, target)) == 1);
data1 = ds(vi, :);
target = 'subgroupB';
vi = find(cellfun('length', regexp(ds.Subgroup, target)) == 1);
data2 = ds(vi, :);
绘制网格图。使用按住
在一个图形上绘制多个图层
t1 = sbiotrellis(data1, 'Group', 'ValueX', 'ValueY', 'LineStyle', 'none', 'Marker', 'o', 'MarkerEdgeColor', [1,0,0], 'MarkerSize', 4, 'MarkerFaceColor', [1,0,0]);
hold on
t2 = sbiotrellis(data2, 'Group', 'ValueX', 'ValueY', 'LineStyle', 'none', 'Marker', 'o', 'MarkerEdgeColor', [0,0,1], 'MarkerSize', 4, 'MarkerFaceColor', [0,0,1]);
t2.labelx = 'X';
t2.labely = 'Y';
t2.plottitle = 'My Trellis Plot';
绘制到这一点:
捕获gcf,它为当前图形的父图形提供句柄
bx = gcf
% bx =
%
% Figure (SimBiologyTrellisPlot) with properties:
%
% Number: 2
% Name: ''
% Color: [0.9400 0.9400 0.9400]
% Position: [415 124 518 384]
% Units: 'pixels'
%
% Show all properties
使用父句柄,获取其子对象的属性
bx1 = bx.Children
% bx1 =
%
% 6x1 graphics array:
%
% Axes (Group "group4")
% Axes (Group "group3")
% Axes (Group "group1")
% Legend (ValueY, ValueY)
% Axes (Group "group2")
% Axes (BackgroundAxes)
现在,您可以看到bx句柄有6个子对象(5个轴和1个图例)。儿童的属性可以按如下方式操作
要获取每个子级的参数列表,请执行以下操作
get(bx1(1))
% ALim: [0 1]
% ALimMode: 'auto'
% ActivePositionProperty: 'position'
% AmbientLightColor: [1 1 1]
% BeingDeleted: 'off'
% Box: 'on'
% BoxStyle: 'back'
% BusyAction: 'queue'
% ButtonDownFcn: {3x1 cell}
% CLim: [0 1]
% CLimMode: 'auto'
% CameraPosition: [0.1359 0.0838 17.3205]
% CameraPositionMode: 'auto'
% CameraTarget: [0.1359 0.0838 0]
% CameraTargetMode: 'auto'
% CameraUpVector: [0 1 0]
% CameraUpVectorMode: 'auto'
% CameraViewAngle: 6.6086
% CameraViewAngleMode: 'auto'
% Children: [2x1 Line]
% Clipping: 'on'
% ClippingStyle: '3dbox'
% Color: [1 1 1]
% ColorOrder: [7x3 double]
% ColorOrderIndex: 3
% CreateFcn: ''
% CurrentPoint: [2x3 double]
% DataAspectRatio: [2.2045 2.2974 1]
% DataAspectRatioMode: 'auto'
% DeleteFcn: ''
% FontAngle: 'normal'
% FontName: 'Helvetica'
% FontSize: 8
% FontSmoothing: 'on'
% FontUnits: 'points'
% FontWeight: 'normal'
% GridAlpha: 0.1500
% GridAlphaMode: 'auto'
% GridColor: [0.1500 0.1500 0.1500]
% GridColorMode: 'auto'
% GridLineStyle: '-'
% HandleVisibility: 'on'
% HitTest: 'on'
% Interruptible: 'on'
% LabelFontSizeMultiplier: 1.1000
% Layer: 'bottom'
% LineStyleOrder: '-'
% LineStyleOrderIndex: 1
% LineWidth: 0.5000
% MinorGridAlpha: 0.2500
% MinorGridAlphaMode: 'auto'
% MinorGridColor: [0.1000 0.1000 0.1000]
% MinorGridLineStyle: ':'
% NextPlot: 'replace'
% OuterPosition: [172.4400 6.7600 289.2000 211.0400]
% Parent: [1x1 Figure]
% PickableParts: 'visible'
% PlotBoxAspectRatio: [1 0.8046 0.8046]
% PlotBoxAspectRatioMode: 'auto'
% Position: [239 49 174 140]
% Projection: 'orthographic'
% Selected: 'off'
% SelectionHighlight: 'on'
% SortMethod: 'childorder'
% Tag: ''
% TickDir: 'in'
% TickDirMode: 'auto'
% TickLabelInterpreter: 'tex'
% TickLength: [0.0100 0.0250]
% TightInset: [0 1.4852e-06 0 0]
% Title: [1x1 Text]
% TitleFontSizeMultiplier: 1.1000
% TitleFontWeight: 'bold'
% Type: 'axes'
% UIContextMenu: []
% Units: 'pixels'
% UserData: []
% View: [0 90]
% Visible: 'on'
% XAxisLocation: 'bottom'
% XColor: [0.1500 0.1500 0.1500]
% XColorMode: 'auto'
% XDir: 'normal'
% XGrid: 'off'
% XLabel: [1x1 Text]
% XLim: [-2.0686 2.3405]
% XLimMode: 'manual'
% XMinorGrid: 'off'
% XMinorTick: 'off'
% XScale: 'linear'
% XTick: [-2 -1 0 1 2]
% XTickLabel: ''
% XTickLabelMode: 'manual'
% XTickLabelRotation: 0
% XTickMode: 'auto'
% YAxisLocation: 'left'
% YColor: [0.1500 0.1500 0.1500]
% YColorMode: 'auto'
% YDir: 'normal'
% YGrid: 'off'
% YLabel: [1x1 Text]
% YLim: [-2.2136 2.3813]
% YLimMode: 'manual'
% YMinorGrid: 'off'
% YMinorTick: 'off'
% YScale: 'linear'
% YTick: [-2 -1 0 1 2]
% YTickLabel: ''
% YTickLabelMode: 'manual'
% YTickLabelRotation: 0
% YTickMode: 'auto'
% ZColor: [0.1500 0.1500 0.1500]
% ZColorMode: 'auto'
% ZDir: 'normal'
% ZGrid: 'off'
% ZLabel: [1x1 Text]
% ZLim: [-1 1]
% ZLimMode: 'auto'
% ZMinorGrid: 'off'
% ZMinorTick: 'off'
% ZScale: 'linear'
% ZTick: [-1 0 1]
% ZTickLabel: ''
% ZTickLabelMode: 'auto'
% ZTickLabelRotation: 0
% ZTickMode: 'auto'
get(bx1(1), 'ZGrid')
%ans =
%
%off
set(bx1(1), 'ZGrid', 'on')
要获取子级参数的值,请执行以下操作
get(bx1(1))
% ALim: [0 1]
% ALimMode: 'auto'
% ActivePositionProperty: 'position'
% AmbientLightColor: [1 1 1]
% BeingDeleted: 'off'
% Box: 'on'
% BoxStyle: 'back'
% BusyAction: 'queue'
% ButtonDownFcn: {3x1 cell}
% CLim: [0 1]
% CLimMode: 'auto'
% CameraPosition: [0.1359 0.0838 17.3205]
% CameraPositionMode: 'auto'
% CameraTarget: [0.1359 0.0838 0]
% CameraTargetMode: 'auto'
% CameraUpVector: [0 1 0]
% CameraUpVectorMode: 'auto'
% CameraViewAngle: 6.6086
% CameraViewAngleMode: 'auto'
% Children: [2x1 Line]
% Clipping: 'on'
% ClippingStyle: '3dbox'
% Color: [1 1 1]
% ColorOrder: [7x3 double]
% ColorOrderIndex: 3
% CreateFcn: ''
% CurrentPoint: [2x3 double]
% DataAspectRatio: [2.2045 2.2974 1]
% DataAspectRatioMode: 'auto'
% DeleteFcn: ''
% FontAngle: 'normal'
% FontName: 'Helvetica'
% FontSize: 8
% FontSmoothing: 'on'
% FontUnits: 'points'
% FontWeight: 'normal'
% GridAlpha: 0.1500
% GridAlphaMode: 'auto'
% GridColor: [0.1500 0.1500 0.1500]
% GridColorMode: 'auto'
% GridLineStyle: '-'
% HandleVisibility: 'on'
% HitTest: 'on'
% Interruptible: 'on'
% LabelFontSizeMultiplier: 1.1000
% Layer: 'bottom'
% LineStyleOrder: '-'
% LineStyleOrderIndex: 1
% LineWidth: 0.5000
% MinorGridAlpha: 0.2500
% MinorGridAlphaMode: 'auto'
% MinorGridColor: [0.1000 0.1000 0.1000]
% MinorGridLineStyle: ':'
% NextPlot: 'replace'
% OuterPosition: [172.4400 6.7600 289.2000 211.0400]
% Parent: [1x1 Figure]
% PickableParts: 'visible'
% PlotBoxAspectRatio: [1 0.8046 0.8046]
% PlotBoxAspectRatioMode: 'auto'
% Position: [239 49 174 140]
% Projection: 'orthographic'
% Selected: 'off'
% SelectionHighlight: 'on'
% SortMethod: 'childorder'
% Tag: ''
% TickDir: 'in'
% TickDirMode: 'auto'
% TickLabelInterpreter: 'tex'
% TickLength: [0.0100 0.0250]
% TightInset: [0 1.4852e-06 0 0]
% Title: [1x1 Text]
% TitleFontSizeMultiplier: 1.1000
% TitleFontWeight: 'bold'
% Type: 'axes'
% UIContextMenu: []
% Units: 'pixels'
% UserData: []
% View: [0 90]
% Visible: 'on'
% XAxisLocation: 'bottom'
% XColor: [0.1500 0.1500 0.1500]
% XColorMode: 'auto'
% XDir: 'normal'
% XGrid: 'off'
% XLabel: [1x1 Text]
% XLim: [-2.0686 2.3405]
% XLimMode: 'manual'
% XMinorGrid: 'off'
% XMinorTick: 'off'
% XScale: 'linear'
% XTick: [-2 -1 0 1 2]
% XTickLabel: ''
% XTickLabelMode: 'manual'
% XTickLabelRotation: 0
% XTickMode: 'auto'
% YAxisLocation: 'left'
% YColor: [0.1500 0.1500 0.1500]
% YColorMode: 'auto'
% YDir: 'normal'
% YGrid: 'off'
% YLabel: [1x1 Text]
% YLim: [-2.2136 2.3813]
% YLimMode: 'manual'
% YMinorGrid: 'off'
% YMinorTick: 'off'
% YScale: 'linear'
% YTick: [-2 -1 0 1 2]
% YTickLabel: ''
% YTickLabelMode: 'manual'
% YTickLabelRotation: 0
% YTickMode: 'auto'
% ZColor: [0.1500 0.1500 0.1500]
% ZColorMode: 'auto'
% ZDir: 'normal'
% ZGrid: 'off'
% ZLabel: [1x1 Text]
% ZLim: [-1 1]
% ZLimMode: 'auto'
% ZMinorGrid: 'off'
% ZMinorTick: 'off'
% ZScale: 'linear'
% ZTick: [-1 0 1]
% ZTickLabel: ''
% ZTickLabelMode: 'auto'
% ZTickLabelRotation: 0
% ZTickMode: 'auto'
get(bx1(1), 'ZGrid')
%ans =
%
%off
set(bx1(1), 'ZGrid', 'on')
要自定义每个子级的参数,请执行以下操作
get(bx1(1))
% ALim: [0 1]
% ALimMode: 'auto'
% ActivePositionProperty: 'position'
% AmbientLightColor: [1 1 1]
% BeingDeleted: 'off'
% Box: 'on'
% BoxStyle: 'back'
% BusyAction: 'queue'
% ButtonDownFcn: {3x1 cell}
% CLim: [0 1]
% CLimMode: 'auto'
% CameraPosition: [0.1359 0.0838 17.3205]
% CameraPositionMode: 'auto'
% CameraTarget: [0.1359 0.0838 0]
% CameraTargetMode: 'auto'
% CameraUpVector: [0 1 0]
% CameraUpVectorMode: 'auto'
% CameraViewAngle: 6.6086
% CameraViewAngleMode: 'auto'
% Children: [2x1 Line]
% Clipping: 'on'
% ClippingStyle: '3dbox'
% Color: [1 1 1]
% ColorOrder: [7x3 double]
% ColorOrderIndex: 3
% CreateFcn: ''
% CurrentPoint: [2x3 double]
% DataAspectRatio: [2.2045 2.2974 1]
% DataAspectRatioMode: 'auto'
% DeleteFcn: ''
% FontAngle: 'normal'
% FontName: 'Helvetica'
% FontSize: 8
% FontSmoothing: 'on'
% FontUnits: 'points'
% FontWeight: 'normal'
% GridAlpha: 0.1500
% GridAlphaMode: 'auto'
% GridColor: [0.1500 0.1500 0.1500]
% GridColorMode: 'auto'
% GridLineStyle: '-'
% HandleVisibility: 'on'
% HitTest: 'on'
% Interruptible: 'on'
% LabelFontSizeMultiplier: 1.1000
% Layer: 'bottom'
% LineStyleOrder: '-'
% LineStyleOrderIndex: 1
% LineWidth: 0.5000
% MinorGridAlpha: 0.2500
% MinorGridAlphaMode: 'auto'
% MinorGridColor: [0.1000 0.1000 0.1000]
% MinorGridLineStyle: ':'
% NextPlot: 'replace'
% OuterPosition: [172.4400 6.7600 289.2000 211.0400]
% Parent: [1x1 Figure]
% PickableParts: 'visible'
% PlotBoxAspectRatio: [1 0.8046 0.8046]
% PlotBoxAspectRatioMode: 'auto'
% Position: [239 49 174 140]
% Projection: 'orthographic'
% Selected: 'off'
% SelectionHighlight: 'on'
% SortMethod: 'childorder'
% Tag: ''
% TickDir: 'in'
% TickDirMode: 'auto'
% TickLabelInterpreter: 'tex'
% TickLength: [0.0100 0.0250]
% TightInset: [0 1.4852e-06 0 0]
% Title: [1x1 Text]
% TitleFontSizeMultiplier: 1.1000
% TitleFontWeight: 'bold'
% Type: 'axes'
% UIContextMenu: []
% Units: 'pixels'
% UserData: []
% View: [0 90]
% Visible: 'on'
% XAxisLocation: 'bottom'
% XColor: [0.1500 0.1500 0.1500]
% XColorMode: 'auto'
% XDir: 'normal'
% XGrid: 'off'
% XLabel: [1x1 Text]
% XLim: [-2.0686 2.3405]
% XLimMode: 'manual'
% XMinorGrid: 'off'
% XMinorTick: 'off'
% XScale: 'linear'
% XTick: [-2 -1 0 1 2]
% XTickLabel: ''
% XTickLabelMode: 'manual'
% XTickLabelRotation: 0
% XTickMode: 'auto'
% YAxisLocation: 'left'
% YColor: [0.1500 0.1500 0.1500]
% YColorMode: 'auto'
% YDir: 'normal'
% YGrid: 'off'
% YLabel: [1x1 Text]
% YLim: [-2.2136 2.3813]
% YLimMode: 'manual'
% YMinorGrid: 'off'
% YMinorTick: 'off'
% YScale: 'linear'
% YTick: [-2 -1 0 1 2]
% YTickLabel: ''
% YTickLabelMode: 'manual'
% YTickLabelRotation: 0
% YTickMode: 'auto'
% ZColor: [0.1500 0.1500 0.1500]
% ZColorMode: 'auto'
% ZDir: 'normal'
% ZGrid: 'off'
% ZLabel: [1x1 Text]
% ZLim: [-1 1]
% ZLimMode: 'auto'
% ZMinorGrid: 'off'
% ZMinorTick: 'off'
% ZScale: 'linear'
% ZTick: [-1 0 1]
% ZTickLabel: ''
% ZTickLabelMode: 'auto'
% ZTickLabelRotation: 0
% ZTickMode: 'auto'
get(bx1(1), 'ZGrid')
%ans =
%
%off
set(bx1(1), 'ZGrid', 'on')
自定义子地块、图例和标题的属性
%subplot 4
bx1(1).Title.String = 'Group 4';
bx1(1).Title.Position = [0.1359, 2.6, 0];
bx1(1).Title.FontWeight = 'bold';
%subplot 3
bx1(2).Title.String = 'Group 3';
bx1(2).Title.Position = [0.1359, 2.6, 0];
bx1(2).Title.FontWeight = 'bold';
%subplot 1
bx1(3).Title.String = 'Group 1';
bx1(3).Title.Position = [0.1359, 2.6, 0];
bx1(3).Title.FontWeight = 'bold';
%legend text, box, and location
bx1(4).String = {'SubgroupA', 'SubgroupB'};
bx1(4).Position = [397.2451 185 109.7549 29.2715];
h =findobj('type', 'legend');
set(h, 'Box', 'off');
%subplot 2
bx1(5).Title.String = 'Group 2';
bx1(5).Title.Position = [0.1359, 2.6, 0];
bx1(5).Title.FontWeight = 'bold';
% Title location
set(bx1(6), 'Position', [30, 30, 390, 324]);
在评估子句柄之后,我们会看到此解决方案末尾显示的最终绘图
图形的其他属性也可以修改,如果查看sbiotrllis的源代码('edit sbiotrllis'
)或键入plot对象,然后键入字母和制表符完成(t2.u
),则可以获得属性或隐藏属性的列表,这些属性或隐藏属性可在渲染绘图后进行操作
性质
hFig;
nPlots;
plots;
属性(隐藏)
输出:
R-晶格-xyplot:
Matlab-sbiotrellis:
您是否考虑过
ggplot2
?或者你的意思是你只想在MATLAB中使用它?重读时,我说不出来。在我看来,MATLAB绘图例程中有一种机制,可以合并绘图,并在sbiotrellis
的第4个参数中指定组。没有安装MATLAB会阻止我做进一步的调查。我原以为,以一种可以复制粘贴到MATLAB会话中的格式呈现数据,会从那些有这种访问权限的人那里获得更多的兴趣。嗨,Satish。这是非常有用的。仅关于每个单独绘图的重命名,当进入部分时:bx=gcf;bx1=bx.儿童;我得到错误:尝试引用非结构数组的字段。这导致无法反映对独立图表标题的编辑。请在从命令行渲染网格图后尝试捕获gcf,并查看是否出现相同的错误。我现在不在我的桌子前面。当我回来时,我会发布每个捕获的输出。是的,我就是这么做的。我在bx=gcf之前运行了所有代码;行,确认显示了绘图,并运行代码的其余部分,我仍然得到相同的错误。另外,鉴于bx1结构有五个字段,并且代码试图索引字段6,我在最后一个关于标题位置的命令上得到了一个错误。我得到了一个错误:索引超过了矩阵维数。(不确定这是否与第一个错误有关)