r - r 中的 somatoChart(绘图或 ggplot)

标签 r ggplot2 plotly

我正在尝试制作somatoChart的复制品来表征一些运动员的体型,我需要一些调整才能得到我期望的结果,左图是我的代码,右图是我希望的结果。

enter image description here

x <- c(0,-6,6,0,-4.5,4.5,0)
y <- c(12,-6,-6,0,4.5,4.5,-7.5)
par(mar = c(2,0,0,2), mgp = c(2,1,0))
plot(x,y,pch = 20,xlab = " ",ylab = " ",xlim = c(-8,8), ylim = c(-10,16),las = 1, col = "white",axes = F)
axis(4, las = 1, yaxp = c(-10,16,13),cex.axis=0.8)
axis(1, xaxp = c(-8, 8, 16),cex.axis=0.8)
# Segmentes
segments(x0 = 0, y0=-7.5, x1 = 0, y1 = 12, lty = 2)
segments(x0 = -6, y0=-6, x1 = 4.5, y1 = 4.5, lty = 2)
segments(x0 = 6, y0=-6, x1 = -4.5, y1 = 4.5, lty = 2)
# text
windowsFonts(B=windowsFont("Bookman Old Style"))
text(0,13,"MESOMORPH", cex = 0.6,family="B", font = 2)
text(-6,-8,"ENDOMORPH",cex = 0.6,family="B", font = 2)
text(6,-8,"ECTOMORPH", cex = 0.6,family="B", font = 2)
# curves
segments(x0 = -4.5, y0=4.5, x1 = 0, y1 = 12)
segments(x0 = -4.5, y0=4.5, x1 = -6, y1 = -6)
segments(x0 = 0, y0=-7.5, x1 = -6, y1 = -6)
segments(x0 = 0, y0=-7.5, x1 = 6, y1 = -6)
segments(x0 = 4.5, y0=4.5, x1 = 6, y1 = -6)
segments(x0 = 4.5, y0=4.5, x1 = 0, y1 = 12)

请读者提出建议?

最佳答案

也许使用xspline可以解决您的问题:

x <- c(0,-6,6,0,-4.5,4.5,0)
y <- c(12,-6,-6,0,4.5,4.5,-7.5)
par(mar = c(2,0,0,2), mgp = c(2,1,0))
plot(x,y,pch = 20,xlab = " ",ylab = " ",xlim = c(-8,8), ylim = c(-10,16),las = 1, col = "white",axes = F)
axis(4, las = 1, yaxp = c(-10,16,13),cex.axis=0.8)
axis(1, xaxp = c(-8, 8, 16),cex.axis=0.8)
# Segmentes
segments(x0 = 0, y0=-7.5, x1 = 0, y1 = 12, lty = 2)
segments(x0 = -6, y0=-6, x1 = 4.5, y1 = 4.5, lty = 2)
segments(x0 = 6, y0=-6, x1 = -4.5, y1 = 4.5, lty = 2)
# text
windowsFonts(B=windowsFont("Bookman Old Style"))
text(0,13,"MESOMORPH", cex = 0.6,family="B", font = 2)
text(-6,-8,"ENDOMORPH",cex = 0.6,family="B", font = 2)
text(6,-8,"ECTOMORPH", cex = 0.6,family="B", font = 2)

xspline(y = c(-6, 4.5, 12), x =  c(-6, -4.5, 0), shape = -1, lty = 2)
xspline(y = c(-6, -7.5,-6), x =  c(-6, 0, 6), shape = -1, lty = 2)
xspline(y = c(-6, 4.5, 12), x = c(6, 4.5, 0),  shape = -1, lty = 2)

enter image description here

关于r - r 中的 somatoChart(绘图或 ggplot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49704219/

相关文章:

r - 在ggplot2中创建一个新的比例

r - 如何为面添加不同的线

r - 如何将子图应用于具有辅助 y 轴的图列表

python - 如何防止plotly自动出图

r - 测试缓冲区是否已在 R 中刷新

r - 将行中的所有元素与行中的最大值相除 - 更快的方法

r - apply 函数 - 自定义函数最后返回 NULL

r - 如何在R中手动更改ggplot2图例的文本颜色?

python - 在 Jupyter 笔记本中运行 Dash 时出现问题

r - 加速 R 中的 lmer 函数