【发布时间】:2022-01-07 00:26:04
【问题描述】:
我正在使用 R Base 绘图。我需要对两列进行子集化,其中一列是性别=女性,另一列是 Measure.Variables=预期寿命。由于 Measure.Variables 列有两个值“预期寿命”和“死亡率”。
此外,我正在尝试手动设置 y 和 x 轴的中断和限制,但我无法这样做。我附上了一张我想添加的休息和限制的图片。
你能帮我解决这个问题吗?我想将 y 轴的中断设置为 break=c(30,40,50,60,70,80),将 x 轴的中断设置为 break=c(1900,1920,1940,1960,1980,2000)。无论数据是否可用,我都希望显示这些限制。
我正在使用以下代码,当我在子集语句中添加第二个条件时,它给了我一个错误。否则,它可以在没有 Measure.Variables==Life Expectancy 命令的情况下正常工作。
下面是数据的输出
structure(list(Measure.Variables = c("Life Expectancy", "Life Expectancy",
"Life Expectancy", "Mortality", "Life Expectancy", "Life Expectancy"
), Race = c("All Races", "All Races", "All Races", "All Races",
"All Races", "All Races"), Sex = c("Both Sexes", "Both Sexes",
"Both Sexes", "Both Sexes", "Both Sexes", "Both Sexes"), Year = 1900:1905,
Average.Life.Expectancy = c(47.3, 49.1, 51.5, 50.5, 47.6,
48.7), Mortality = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_)), row.names = c(NA, 6L), class = "data.frame")
我正在使用以下代码
with(subset(LF, Sex == "Male", Measure.Variables == "Life Expectancy"),
plot(Year, Average.Life.Expectancy, col="red", pch=17,
main="Male Life Expectancy", ylab="Life Expectancy"))
为响应阿黛尔而编辑,y 值仍未显示。请看这张图Graph after Adele's suggestion
【问题讨论】:
-
我建议你考虑一个风格指南,例如jef.works/R-style-guide
-
@jay.sf 谢谢!!您还可以帮助手动设置 R 基础绘图中的中断吗?我在 x 轴上有几年,在 y 轴上有预期寿命,以下是我试图为 y xis =c(30,40,50,60,70,80) 为 x xis =c( 1900,1920,1940,1960,1980,2000)