I have been trying to plot a surface from the following data
z = structure(c(-0.901395069908367, -0.889270928722939, -0.860498522734513,
-0.81162341264254, -0.741289594106116, -0.648766092305491, -0.534349208041337,
-0.399845199903741, -0.249855361975959, -0.0897251475874947,
0.0746259084372811, 0.236078784565598, 0.387628389740501, 0.523650864552803,
0.640660077165393, 0.737009776188609, 0.812016566072894, 0.866304532376613,
0.901568276352029, 0.920360368688146, -0.882227601197732, -0.878930792308559,
-0.858884362955903, -0.817800704213168, -0.753368006803807, -0.66449012298986,
-0.551487546899363, -0.416392170535135, -0.264538800185667, -0.101517270999555,
0.0666888146596484, 0.232341014061553, 0.38749240207806, 0.524415630048401,
0.640084827807316, 0.733314764232348, 0.80301493330195, 0.850313451774813,
0.877753646407397, 0.88963725156383, -0.847475017108294, -0.85307262716591,
-0.842574356483547, -0.810407792264141, -0.752945080664338, -0.668633289794334,
-0.558328099823412, -0.425304557346782, -0.275029532996457, -0.112783840666026,
0.0558934516670588, 0.222087091307297, 0.377068406557726, 0.512939126260687,
0.625804332859799, 0.714297176038507, 0.777443068815926, 0.816496676689634,
0.836080905877643, 0.842475340232409, -0.794484724176902, -0.808695744871725,
-0.807980823999131, -0.784767233676891, -0.734736669998055, -0.656413316398881,
-0.550933437104475, -0.423358808055153, -0.278506129655091, -0.120866143889105,
0.0433499698178821, 0.204910622000686, 0.354654201404564, 0.486317568693109,
0.594088245807692, 0.675931270610041, 0.731821498045365, 0.763893435823378,
0.777321922428609, 0.779323256471572, -0.721035151310193, -0.742489349579308,
-0.750777748074823, -0.736960272021206, -0.694879238996425, -0.623996082218869,
-0.526887497647841, -0.408661964047638, -0.273737770263875, -0.125356088457535,
0.0291260358276813, 0.180223786309321, 0.319893992902204, 0.442102408314768,
0.541837117518898, 0.616080337260617, 0.665334074499435, 0.692652951176559,
0.702073015925212, 0.70014294591476, -0.62634454997212, -0.653025685850572,
-0.669123471922786, -0.664287895904395, -0.631116905593864, -0.570128054300068,
-0.484723579158402, -0.37958495150019, -0.258935393270118, -0.125654469777847,
0.0133852524560905, 0.148202883542656, 0.272475225263341, 0.380626909415146,
0.468703561895249, 0.534264335754137, 0.577639625419541, 0.60157076785374,
0.608220344177334, 0.604222909445142, -0.512344852448439, -0.541555029880959,
-0.562961881990283, -0.566220190988011, -0.543544051940367, -0.494559171738039,
-0.423645361722741, -0.335975893586483, -0.235168989845246, -0.122814581317589,
-0.00544137604122541, 0.107867126384677, 0.212427329329769, 0.302909552255676,
0.376324025384858, 0.431708923178868, 0.469101279162711, 0.489651660797114,
0.495110354415309, 0.491340850885662, -0.381309022143908, -0.410783959771577,
-0.435389666816656, -0.445770602448373, -0.433004934811996, -0.397491381573017,
-0.344416516747127, -0.278325021678467, -0.202169912833898, -0.117875088678067,
-0.0294056925490386, 0.0579458089153829, 0.140043646562862, 0.211102719345402,
0.267777922857105, 0.311419904628903, 0.341855012664907, 0.358730431743406,
0.364518297473459, 0.363240891735784, -0.234818927315893, -0.262530061791553,
-0.288066101196323, -0.304121353637761, -0.30170450668554, -0.28177357685378,
-0.249245809281562, -0.208160977212965, -0.161032375996862, -0.109589438945933,
-0.0551612509212895, 0.00133984767391211, 0.057278847069763,
0.106580792282658, 0.145980466712106, 0.176865463055578, 0.199541843346534,
0.213637631708287, 0.221141803400151, 0.223933303241254, -0.0765199640532891,
-0.0999824673920636, -0.124480103191673, -0.144232572992753,
-0.152909373229339, -0.150600362070916, -0.140686596578978, -0.127276509402488,
-0.112080967355925, -0.0959971815561244, -0.0777115240226103,
-0.0558079539376473, -0.0309319906934945, -0.00646144860933681,
0.0146751773765434, 0.0330917549345564, 0.0489244989926914, 0.0618218644227028,
0.0717616083498969, 0.0786560810115295, 0.0876811192087983, 0.0697400208872219,
0.0487788538006448, 0.0269055967832573, 0.00740020063383676,
-0.00851809193381578, -0.0224246952709679, -0.0379057923626619,
-0.0560184192271167, -0.0760996990081513, -0.0948316128077681,
-0.108936070754438, -0.11749086793581, -0.120509248006123, -0.118650306371636,
-0.112254286791432, -0.102307567397665, -0.0903088095336494,
-0.0780987508225131, -0.0677553904853005, 0.252646739761749,
0.240806809421569, 0.223572332072489, 0.200384337470906, 0.171532673986367,
0.138038979275939, 0.099610125026476, 0.0551872652032152, 0.00478723497468162,
-0.0502739399996399, -0.105903142355679, -0.155416635318454,
-0.196689276852176, -0.227281308354055, -0.245510439464005, -0.251680533953819,
-0.248151683021562, -0.237873594096041, -0.224643816034859, -0.211430976424376,
0.412083487867202, 0.405482299038271, 0.391485749933225, 0.366992663926528,
0.329942922079822, 0.280376438559889, 0.21975434771463, 0.148349710354354,
0.067171462923436, -0.0202860188429894, -0.109178441152915, -0.191951597181515,
-0.263855321315342, -0.320191772332899, -0.358801475967917, -0.379017864632865,
-0.383976898947948, -0.377538947209839, -0.364498733398927, -0.348859987545735,
0.56036438679084, 0.557157741301204, 0.545344926607978, 0.518682844541529,
0.473913612380679, 0.411336768404074, 0.332508721380021, 0.237443242494199,
0.128967481760446, 0.0132250816174241, -0.104269156052445, -0.215831154932383,
-0.314796148353222, -0.395698871967524, -0.454216961405671, -0.48939478748932,
-0.504182544361458, -0.503121698419469, -0.491894461703185, -0.47520035398754,
0.69476361802097, 0.692646546646937, 0.680749564713899, 0.651398622302503,
0.600078777493038, 0.527047463117019, 0.433013134286506, 0.318393751312497,
0.187931883938919, 0.0485415189557076, -0.0924602858559757, -0.227761779764008,
-0.349631680299174, -0.451607698807979, -0.528541780407822, -0.578524956928284,
-0.603804265252205, -0.609120896979876, -0.601289608746566, -0.585540179764667,
0.813266228275571, 0.810506038003487, 0.796844139738609, 0.764453028221258,
0.707450116347561, 0.62571592477967, 0.519614498955702, 0.390246591949968,
0.243341967239212, 0.0861522807453793, -0.0736279085948786, -0.227866185933834,
-0.367494474867194, -0.485506871937427, -0.577239558663347, -0.640408877746243,
-0.676403050530757, -0.690576743314995, -0.688678577814345, -0.676429718923359,
0.914072702896753, 0.908848990145119, 0.891584857432632, 0.855267032404637,
0.793376249877853, 0.705115303908622, 0.590546028589521, 0.451414245822445,
0.293839303219628, 0.124680267405642, -0.0479108928191147, -0.215106602279399,
-0.366655256382102, -0.495161152151185, -0.598221357198254, -0.673169863459292,
-0.720490363187427, -0.745181116693124, -0.752125846282775, -0.746149917016764,
0.996287679954195, 0.986818541859255, 0.964596295451714, 0.923525516175463,
0.857144605481058, 0.763534587185077, 0.643488846938705, 0.499393204416234,
0.337016085032734, 0.161976880625728, -0.016856861210691, -0.190116150981591,
-0.348063434276771, -0.484140957679691, -0.596125932517742, -0.681344256408742,
-0.740038823605145, -0.775737430336284, -0.792663253588154, -0.794732374768692,
1.06061439454562, 1.04544076891118, 1.01703653222416, 0.970302993290611,
0.899469571463457, 0.801462174884477, 0.678313451930742, 0.533231256117207,
0.370392935930347, 0.195249209837787, 0.0162592847293909, -0.157296899896799,
-0.317350547718038, -0.458168879616197, -0.576604274565736, -0.670309502260843,
-0.739228543711965, -0.785405276981519, -0.812214818331992, -0.822803313137382,
1.10885869520928, 1.08711267560539, 1.05160959155953, 0.998207666512568,
0.922707795799498, 0.822302049371678, 0.698635387488528, 0.554846624007452,
0.394359048691908, 0.223064832052992, 0.0483074128559527, -0.121990772157994,
-0.280872368359659, -0.423065532821516, -0.545072934983457, -0.644763290060129,
-0.721744372269504, -0.777280364350403, -0.813503852239487, -0.832785269227836
), .Dim = c(20L, 20L))
and I have been using the plotly library, for example, with
library(plotly)
fig <- plot_ly(z = ~z, type = "surface", x = seq(0, 1, len = 20), y = seq(0, 1, len = 20))
fig
My problem is that the graph looks strange in that the x-axis and y-axis are much too small. The problem is alleviated if instead I use
fig <- plot_ly(z = ~z, type = "surface")
fig
but then the axis ticks are not correct since the data were collected in the [0,1]-cube. Is it possible to resize the first plot so that it looks more like the second one but with the correct axis ticks? Thank you.
CodePudding user response:
Based on this link,
library(plotly)
fig <- plot_ly(z = ~z, type = "surface", x = seq(0, 1, len = 20), y = seq(0, 1, len = 20)) %>%
layout(scene = list(aspectratio = list(x=1, y=1, z=1)))
fig