Domanda

I have doubts about how to make the line graphs. Below you will find a data.frame and a variable with an integer value. I want to use power_value as X axis values​​, the total_epc and found_epc would be the values ​​of the linear plots, and the variable with the integer value would be a constant line.

In addition, I would add the titles of X axis and the Y axis, and a legend indicating where the graph of column 2 corresponds to the values ​​"a", the graph of column 3 is for the "b" values ​​and the constant line would be the "number of items". All the graphics should be in the same plot.

I am new to R and I would like to have an example of how to fix this, to be able to carry out the other graphic data concerning a similar distribution

    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
È stato utile?

Soluzione

You can use for example the ggplot2 package to achieve that.

Reading the data:

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)

Creating the plot:

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")

The resulting plot: enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top