![](/img/trans.png)
[英]How do you increase the space between the axis labels and axis titles in R using functions ggplot() and plot_ly?
[英]Plot_ly in R: How to add proper axis labels and tick-values?
如果M
是矩陣,則
plot_ly(z = M) %>% add_surface()
繪制該矩陣的曲面圖。 意思是,行和列是 x 和 y 值,z 值是矩陣中的元素。
但是,x 軸和 y 軸被標記為與M
的行和列對應的整數。 此外,坐標軸在圖中直接稱為“x”和“y”。
但這不是我想要的。 矩陣M
是使用outer(A, B, someFunction)
,其中A, B
是向量。 所以我實際上希望軸顯示值A
和B
,並且我希望軸標簽顯示"A", "B"
而不是"x", "y"
。
我該怎么做呢?
從他們的文檔中找到: https : //plot.ly/r/figure-labels/
library(plotly)
library(tidyverse)
M <-
matrix(c(1, 2, 3, 1), ncol = 2, nrow = 2)
plot_ly(z = M) %>%
add_surface() %>%
layout(scene = list(xaxis = list(title = "A"), yaxis = list(title = "B")))
您必須在x
和y
設置A
和B
:
library(plotly)
A <- B <- seq(-5, 5, by = 0.2)
z <- outer(A, B, function(x,y) exp(-x^2-y^2))
plot_ly(x = A, y = B, z = z) %>% add_surface() %>%
layout(scene = list(xaxis = list(title = "A"), yaxis = list(title = "B")))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.