[英]linear graphs in R with 4 different variables
我對如何制作折線圖有疑問。 在下面,您將找到一個data.frame和一個帶有整數值的變量。 我想使用power_value
作為X軸值, total_epc
和found_epc
將是線性圖的值,而帶有整數值的變量將是一條恆定線。
另外,我將添加X軸和Y軸的標題,以及一個圖例,該圖例指示第2列的圖形對應於值“ a”,第3列的圖形對應於“ b”值而常數行將是“項目數”。 所有圖形應在同一圖中。
我是R的新手,我想舉個例子來解決這個問題,以便能夠執行與類似分布有關的其他圖形數據
power_value total_epc found_epc
1 31.5 8 1.0000000
2 31.0 6 0.8333333
3 30.5 6 0.8333333
4 30.0 6 0.8333333
5 29.5 7 0.8333333
6 29.0 7 0.8333333
7 28.5 6 0.8333333
8 28.0 6 0.8333333
9 27.5 6 0.8333333
10 27.0 6 0.8333333
11 26.5 6 0.8333333
12 26.0 6 0.8333333
13 25.5 6 0.8333333
14 25.0 6 0.8333333
15 24.5 6 0.8333333
16 24.0 6 0.8333333
17 23.5 6 0.8333333
18 23.0 5 0.6666667
19 22.5 5 0.6666667
20 22.0 5 0.6666667
a<-7
您可以使用例如ggplot2
軟件包來實現這一點。
讀取數據:
df <- read.table(text="rows power_value total_epc found_epc
1 31.5 8 1.0000000
2 31.0 6 0.8333333
3 30.5 6 0.8333333
4 30.0 6 0.8333333
5 29.5 7 0.8333333
6 29.0 7 0.8333333
7 28.5 6 0.8333333
8 28.0 6 0.8333333
9 27.5 6 0.8333333
10 27.0 6 0.8333333
11 26.5 6 0.8333333
12 26.0 6 0.8333333
13 25.5 6 0.8333333
14 25.0 6 0.8333333
15 24.5 6 0.8333333
16 24.0 6 0.8333333
17 23.5 6 0.8333333
18 23.0 5 0.6666667
19 22.5 5 0.6666667
20 22.0 5 0.6666667", header=TRUE)
創建圖:
require(ggplot2)
ggplot(df, aes(x=power_value, y=total_epc)) +
geom_line(color="red") +
geom_point(color="red", shape=20) +
geom_line(aes(x=power_value, y=found_epc), color="blue") +
geom_point(aes(x=power_value, y=found_epc), color="blue", shape=20) +
geom_hline(yintercept=7, color="green")
結果圖:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.