簡體   English   中英

R-創建繪圖網格,然后繪圖數據點

[英]R - create plot grid and then plot data points

我想知道是否有可能僅在R中創建圖的“網格”,然后根據矩陣中的值添加數據點。 例如,我想在X軸上有一些日歷年值,在Y軸上有一些國家的名字。 然后,根據矩陣中的數據,在需要的地方在圖形中添加一個點。 示例數據: Y_labels = c("Austria", "Belgium", "Germany", "Spain")X_labels = c(1990, 1991, 1992, 1993, 1994, 1995) 假設包含要繪制的數據點的向量是x = cbind(c(1991, 1993, 1995),c("Belgium", "Spain", "Belgium")) 然后,在1991年比利時,我將添加一個點/圓/任何位置。感謝您的幫助。 謝謝。

是的你可以!

只需創建一個類型為“ n”的空圖(無)

df <- data.frame(year = c(1992, 1995, 1998, 1999), 
                 country = c("Austria", "Spain", "Spain", "Germany"))

# All the possible countries
all.countries <- c("Austria", "Belgium", "Germany", "Spain");
# Convert df$country to a factor
df$country <- factor(df$country, levels=all.countries)
# yaxt="n" hides the y axis, be sure to specify xlim and ylim
# so that your data fits in the graph!
plot(0, t="n", xlim=c(1990, 2000), ylim=c(1, length(all.countries)), 
     yaxt="n", xlab="Year", ylab="Country")
# Plot a y axis
axis(2, at=1:length(all.countries), labels=all.countries)
# points plots over an existing graph
points(df, pch=20)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM