gpt4 book ai didi

r - 带有代表绝对大小的气泡的气泡图

转载 作者:行者123 更新时间:2023-12-04 02:16:32 25 4
gpt4 key购买 nike

我正在尝试制作一个气泡图,其中每种颜色代表不同的珊瑚物种代码,气泡的大小代表以米为单位的个体大小,但也缩放到 x 或 y 轴,它们也按比例缩放米。

我还想为我目前使用的个人尺寸添加一个额外的图例 plotly在 R 中,但可以在 R 或 Python 中使用其他模块。

我已经能够相对容易地按物种获得颜色,但我正在努力按大小缩放气泡。有没有人这样做过或知道任何秘籍让它工作?

     #Example Data
Species <- c('SSID','PAST','CNAT','SSID','MMEA','PAST')
Dist <- c(7.1,4.0,6.4,8.0,8.1,8.9)
XDist <- runif(6, 0.0, 1.0)
Transect <- c(1,2,1,1,3,2)
Width <- c(10,15,100,45,60,27)
Data <- data.frame(Transect, Species, Dist, XDist, Width)
XDist <- Data$Transect - 1
Data$XDist <- Data$XDist + XDist

library(plotly)

k <- plot_ly(Data, x = ~XDist, y = ~Dist, type = 'scatter', mode =
'markers',
size = ~Width ,marker = list(sizemode = 'diameter', opacity = 1,
symbol = ifelse(data$Disease == 'Y', "circle-open", "circle"),
line = list(width = 5)),
color = ~Species, colors = 'Set1',
hoverinfo = 'text',
text = ~paste('Width:', Width, '<br>Species:', Species)
) %>%
layout(title = 'Coral',
xaxis = list(showgrid = FALSE),
yaxis = list(showgrid = FALSE))

Coral Map

最佳答案

经过深思熟虑并找到了一对卡尺,我想我已经回答了自己的问题。假设宽度 = 1000,高度 = 1000,我的地 block 上的 100 厘米 = 3.72 毫米。 Plotly 似乎根据最大气泡和最小气泡的大小来缩放气泡。默认大小的气泡最大为 2.45mm,最小为 0.21mm。您可以使用这些测量值创建一个比率,以绝对缩放气泡到距离。

    #Data
Species <- c('SSID','PAST','CNAT','SSID','MMEA','PAST')
Coral <- c(1,2,3,4,5,6)
Dist <- c(1,2.4,4.6,3.2,1.2,4.1)
XDist <- c(2,3,0.5,2.3,4.1,2.5)
Transect <- c(1,2,1,1,3,2)
Width <- c(10,15,100,45,60,27)
Disease <- c(0,0,0,1,0,0)
Data <- data.frame(Coral, Transect, Species, Dist, XDist, Width, Disease)

Datamax <- (((max(Data$Width, na.rm = T)*3.72)/100)/2.45)*100
Datamin <- (((min(Data$Width, na.rm = T)*3.72)/100)/0.21)*10
k <- plot_ly(Data, x = ~XDist, y = ~Dist, type = 'scatter',
mode ='markers',
size = ~Width ,marker = list(sizemode = 'diameter', opacity = 0.75,
symbol = ifelse(Data$Disease == 1, "circle-open", "circle"),
line = list(width = 10)),
color = ~Species, colors = 'Set1',
hoverinfo = 'text',
text = ~paste('Width:', Width, '<br>Species:', Species),
width = 1000,
height = 1000,# ) %>%
sizes = c(Datamin,Datamax)) %>%

add_annotations(text = Data$Coral,
xanchor = 'center', showarrow = F) %>%
layout(title = 'Coral',
xaxis = list(showgrid = TRUE,
range = c(-0.25,5.25),
zeroline = T,
showline = T,
mirror = "ticks",
gridcolor = toRGB("grey50"),
gridwidth = 2),
yaxis = list(showgrid = FALSE,
scaleanchor = "x",
rangemode = "nonnegative"))
k
export(k,file = "Test.CoralMap.png")

Test Coral Map

关于r - 带有代表绝对大小的气泡的气泡图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48085328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com