How to create a density chart with a data file ?

Hello,
I want to create a density chart which represents the density of grades of each mounth of the year. How to do after the import of data ?
Best regards
Constantin

It is very hard to give specific advice when I do not know what your data look like.
I imagine it has a column named Month, which is a category, and a numeric column named Grade. In the example below, I invent a small data set and make a graph of the density of Grade for each Month. If that is not enough to solve your problem, please post some data. An easy way to do that is to post the output of the dput() function. If your data frame is named DF, post the output of either

dput(DF)

or

dput(head(DF,30))

library(ggplot2)
DF <- data.frame(Month=rep(c("A","B","C"),30),
                 Grade=rnorm(90))
ggplot(DF,aes(x=Grade,color=Month))+geom_density()

Created on 2022-08-03 by the reprex package (v2.0.1)

Hello
Thanks you for your help. My data is this

and my code is this :
mois=read.csv(file.choose(), sep=";", dec=",", header=TRUE)
df1 <- data.frame(mois)
library(ggplot2)
ggplot(df1,aes(x=Grade,color=Month))+geom_density()

but, in the console, I have this error
Error in FUN(X[[i]], ...) : object 'Grade' not found

Output of the fonction
dput(mois)
structure(list(janvier = c(7.5, 7.8, 6.5, 6.7, 7.7, 7, 7.2, 8.3,
6.6, 6.2, 7.7, 9.8, 7, 6.9, 6.3, 10, 6.4, 6.9, 7, 9, 7.1, 7.2,
7.1, 5.8, 7.5, 6.6, 6.8, 7.8, 7, 7.1, 7.5), fevrier = c(6.9,
6.5, 5.2, 7, 6.8, 7.3, 6, 7.5, 8.4, 6.4, 6.5, 6.6, 7.7, 6.4,
5.4, 6.2, 8.2, 8.3, 8.9, 7.6, 6.8, 8, 9.3, 7.4, 6.7, 7.4, 7.6,
6.6, NA, NA, NA), mars = c(7.2, 6.8, 7.7, 7.6, 9.1, 6.9, 6.1,
6.6, 9.9, 7.5, 7.9, 7.3, 6.5, 8.1, 7, 6.8, 7.4, 7.6, 7.8, 3.5,
7, 7.5, 7.7, 7.8, 8.3, 8.2, 8.4, 7.9, 7.8, 6.9, 6.2), avril = c(6,
7, 6.7, 6.9, 7, 7.2, 6.1, 6.9, 7.5, 8, 8.1, 10, 9.6, 8.7, 8.8,
7.8, 9.7, 8.4, 7.9, 7.7, 8.5, 7.5, 6.9, 7, 6.4, 6.1, 7.8, 8.3,
6.5, 10, NA), mai = c(8, 8.1, 7.6, 10, 6.6, 8.6, 7.9, 7.4, 8.5,
7.8, 8.3, 8.4, 7.6, 9.2, 7.7, 7.9, 8, 7.5, 7.9, 8.7, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10), juin = c(10, 10, 10, 10,
10, 7.5, 7.4, 6.7, 6.9, 7.6, 7.5, 7.8, 7.6, 7.9, 8.1, 8, 8.3,
8.8, 8.9, 7.9, 7.1, 6.8, 6.5, 6.6, 7.8, 7.9, 7.3, 8.4, 8.2, 7.5,
NA), juillet = c(7.4, 7.7, 7.9, 7.3, 8.7, 9.4, 7.5, 8.2, 9, 7.1,
7.7, 7.6, 7.4, 8.4, 7.2, 7.8, 6.4, 8, 8.8, 8.3, 6.8, 7.9, 6.5,
8.1, 7.6, 7.9, 9.7, 8.3, 7.8, 6.8, 7)), class = "data.frame", row.names = c(NA,
-31L))

your data need to be converted into the right (= long) format before you can put it into ggplot.

# convert data in the "long" format
mois2 = pivot_longer(mois,
                     cols =everything(),
                     names_to = "month",
                     values_to = "grade")

# show all in one
ggplot(mois2,
       aes(x=grade, color=month)) + 
  geom_density() +
  theme_minimal()


This might be a bit too much to have a good overview

# show individual plots
ggplot(mois2,
       aes(x=grade, color=month)) + 
  geom_density() +
  theme_minimal() + 
  facet_wrap(~ month)

1 Like

Thanks
But, I have an error
Error in pivot_longer(mois, cols = everything(), names_to = "month", values_to = "grade") : **
** could not find function "pivot_longer"

Ah sorry, you need to load
library(tidyverse) (this one includes ggplot and many other nice functions as well)
or
library(tidyr) (only for the pivoting step)

Thanks
I'm evaluating all the days of the year (about my mood) and i want to analyse this data. Do you have some other tips ?

You can maybe think of showing the data as boxplots or violin plots.
And you have to order the plots into the right order (convert to factor)

Since the data are ordered in time, it makes sense to look at them time on the x axis. This makes the series of high values in May and June very obvious.

library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.1.2
library(lubridate)

mois <- structure(
  list(janvier = c(7.5, 7.8, 6.5, 6.7, 7.7, 7, 7.2, 8.3,
                   6.6, 6.2, 7.7, 9.8, 7, 6.9, 6.3, 10, 6.4, 6.9, 7, 9, 7.1, 7.2,
                   7.1, 5.8, 7.5, 6.6, 6.8, 7.8, 7, 7.1, 7.5), 
       fevrier = c(6.9,
                   6.5, 5.2, 7, 6.8, 7.3, 6, 7.5, 8.4, 6.4, 6.5, 6.6, 7.7, 6.4,
                   5.4, 6.2, 8.2, 8.3, 8.9, 7.6, 6.8, 8, 9.3, 7.4, 6.7, 7.4, 7.6,
                   6.6, NA, NA, NA), 
       mars = c(7.2, 6.8, 7.7, 7.6, 9.1, 6.9, 6.1,
                6.6, 9.9, 7.5, 7.9, 7.3, 6.5, 8.1, 7, 6.8, 7.4, 7.6, 7.8, 3.5,
                7, 7.5, 7.7, 7.8, 8.3, 8.2, 8.4, 7.9, 7.8, 6.9, 6.2), 
       avril = c(6,
                 7, 6.7, 6.9, 7, 7.2, 6.1, 6.9, 7.5, 8, 8.1, 10, 9.6, 8.7, 8.8,
                 7.8, 9.7, 8.4, 7.9, 7.7, 8.5, 7.5, 6.9, 7, 6.4, 6.1, 7.8, 8.3,
                 6.5, 10, NA), 
       mai = c(8, 8.1, 7.6, 10, 6.6, 8.6, 7.9, 7.4, 8.5,
               7.8, 8.3, 8.4, 7.6, 9.2, 7.7, 7.9, 8, 7.5, 7.9, 8.7, 10, 10,
               10, 10, 10, 10, 10, 10, 10, 10, 10), 
       juin = c(10, 10, 10, 10,
                10, 7.5, 7.4, 6.7, 6.9, 7.6, 7.5, 7.8, 7.6, 7.9, 8.1, 8, 8.3,
                8.8, 8.9, 7.9, 7.1, 6.8, 6.5, 6.6, 7.8, 7.9, 7.3, 8.4, 8.2, 7.5,
                NA), 
       juillet = c(7.4, 7.7, 7.9, 7.3, 8.7, 9.4, 7.5, 8.2, 9, 7.1,
                   7.7, 7.6, 7.4, 8.4, 7.2, 7.8, 6.4, 8, 8.8, 8.3, 6.8, 7.9, 6.5,
                   8.1, 7.6, 7.9, 9.7, 8.3, 7.8, 6.8, 7)), 
  class = "data.frame", row.names = c(NA, -31L))

MoisLong <- mois |> mutate(DayOfMonth = 1:31) |> 
  pivot_longer(cols = janvier:juillet, names_to = "Month",
               values_to = "Value") |> 
  na.omit() |> 
  mutate(Month = factor(Month, levels = c("janvier","fevrier","mars",
                                          "avril","mai","juin","juillet")),
         Date = make_date(year = 2022, month = as.numeric(Month), day = DayOfMonth)) 

ggplot(MoisLong,aes(Date, Value)) + geom_point() +
  geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2022-08-04 by the reprex package (v2.0.1)

1 Like

Your help is amazing, it's great! Thanks!
I have a question, it's mandatory to write all the grades in the formula ?
list(janvier = c(7.5, 7.8, 6.5, 6.7, 7.7, 7, 7.2, 8.3,
6.6, 6.2, 7.7, 9.8, 7, 6.9, 6.3, 10, 6.4, 6.9, 7, 9, 7.1, 7.2,
7.1, 5.8, 7.5, 6.6, 6.8, 7.8, 7, 7.1, 7.5),
fevrier = c(6.9,
6.5, 5.2, 7, 6.8, 7.3, 6, 7.5, 8.4, 6.4, 6.5, 6.6, 7.7, 6.4,
5.4, 6.2, 8.2, 8.3, 8.9, 7.6, 6.8, 8, 9.3, 7.4, 6.7, 7.4, 7.6,
6.6, NA, NA, NA),
mars = c(7.2, 6.8, 7.7, 7.6, 9.1, 6.9, 6.1,
6.6, 9.9, 7.5, 7.9, 7.3, 6.5, 8.1, 7, 6.8, 7.4, 7.6, 7.8, 3.5,
7, 7.5, 7.7, 7.8, 8.3, 8.2, 8.4, 7.9, 7.8, 6.9, 6.2),
avril = c(6,
7, 6.7, 6.9, 7, 7.2, 6.1, 6.9, 7.5, 8, 8.1, 10, 9.6, 8.7, 8.8,
7.8, 9.7, 8.4, 7.9, 7.7, 8.5, 7.5, 6.9, 7, 6.4, 6.1, 7.8, 8.3,
6.5, 10, NA),
mai = c(8, 8.1, 7.6, 10, 6.6, 8.6, 7.9, 7.4, 8.5,
7.8, 8.3, 8.4, 7.6, 9.2, 7.7, 7.9, 8, 7.5, 7.9, 8.7, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10),
juin = c(10, 10, 10, 10,
10, 7.5, 7.4, 6.7, 6.9, 7.6, 7.5, 7.8, 7.6, 7.9, 8.1, 8, 8.3,
8.8, 8.9, 7.9, 7.1, 6.8, 6.5, 6.6, 7.8, 7.9, 7.3, 8.4, 8.2, 7.5,
NA),
juillet = c(7.4, 7.7, 7.9, 7.3, 8.7, 9.4, 7.5, 8.2, 9, 7.1,
7.7, 7.6, 7.4, 8.4, 7.2, 7.8, 6.4, 8, 8.8, 8.3, 6.8, 7.9, 6.5,
8.1, 7.6, 7.9, 9.7, 8.3, 7.8, 6.8, 7))

Because is very long to rewrite all the grades... It's possible to do this directly since the original (.CSV) data ?

The list of data at the beginning of my code is simply the output of

dput(mois)

I used that because I do not have your csv file. You can run

mois=read.csv(file.choose(), sep=";", dec=",", header=TRUE) # This is your  code from above

MoisLong <- mois |> mutate(DayOfMonth = 1:31) |> 
  pivot_longer(cols = janvier:juillet, names_to = "Month",
               values_to = "Value") |> 
  na.omit() |> 
  mutate(Month = factor(Month, levels = c("janvier","fevrier","mars",
                                          "avril","mai","juin","juillet")),
         Date = make_date(year = 2022, month = as.numeric(Month), day = DayOfMonth)) 

ggplot(MoisLong,aes(Date, Value)) + geom_point() +
  geom_smooth()

I have this error.
Error in mutate():
! Problem while computing Date = make_date(year = 2022, month = as.numeric(Month), day = DayOfMonth).
Caused by error in make_date():
! could not find function "make_date"
Run rlang::last_error() to see where the error occurred.

rlang::last_error()
Error in $<-.data.frame(*tmp*, "call_text", value = c("dplyr::mutate(...)", :
le tableau de remplacement a 6 lignes, le tableau remplacé en a 4

The make_date() function is in the lubridate package. You have to run

library(tidyverse)
library(lubridate)

before running the code. I did include the library() calls in the first posting of my solution but I left them out of the most recent version. That was a mistake on my part.

Start by entering density equation values into two columns of an Excel spreadsheet, with Y values in the column on the left and X values in the column on the right, and then create and format the density graph...

Thanks you, this community is a paradise!

I have the data by the date
Date;Note;Obs;stress;Sommeil;Activite
01/01/2022;7,5;0;2;7,1;17343
02/01/2022;7,8;0;4;7,67;10494
03/01/2022;6,5;0;6;6,45;9349
04/01/2022;6,7;0;4;9,83;6201
05/01/2022;7,7;0;6;7,5;6294
06/01/2022;7;0;3;8,33;7092
07/01/2022;7,2;0;2;6,32;8653
08/01/2022;8,3;0;4;9,33;16374
09/01/2022;6,6;0;1;8,17;15055
10/01/2022;6,2;0;5;6,83;9550
11/01/2022;7,7;0;1;9,17;10449
12/01/2022;9,8;5;8;8;11351
13/01/2022;7;0;3;7,17;9002
14/01/2022;6,9;0;4;9;9768
15/01/2022;6,3;0;6;7,15;15711
16/01/2022;10;7;5;9,33;14341
17/01/2022;6,4;0;6;6,33;7827
18/01/2022;6,9;0;4;7;9522
19/01/2022;7;0;6;8,5;6499
20/01/2022;9;1;6;7,17;10250
21/01/2022;7,1;0;2;6,33;15114
22/01/2022;7,2;0;3;9,5;18985
23/01/2022;7,1;0;7;0,5;40168
24/01/2022;5,8;0;8;6,67;9115
25/01/2022;7,5;0;3;6,33;9398
26/01/2022;6,6;0;3;7,5;9784
27/01/2022;6,8;0;2;7;9690
28/01/2022;7,8;0;3;10;9271
29/01/2022;7;0;2;9,33;15901
30/01/2022;7,1;0;2;7,07;19450
31/01/2022;7,5;0;2;6,5;9453
01/02/2022;6,9;0;6;6,83;9085
02/02/2022;6,5;0;4;8,33;11044
03/02/2022;5,2;-1;7;7,17;8432
04/02/2022;7;0;2;9,33;10259
05/02/2022;6,8;0;1;9,33;13672
06/02/2022;7,3;0;3;10;16965
07/02/2022;6;0;6;6;7475
08/02/2022;7,5;0;5;6,5;9404
09/02/2022;8,4;0;0;8,67;12155
10/02/2022;6,4;0;4;7,33;7413
11/02/2022;6,5;0;6;9,5;6326
12/02/2022;6,6;0;4;8,5;14953
13/02/2022;7,7;0;2;7,67;20149
14/02/2022;6,4;0;4;8,67;11936
15/02/2022;5,4;-1;7;8,67;12722
16/02/2022;6,2;0;5;7,33;16582
17/02/2022;8,2;0;3;9,5;16556
18/02/2022;8,3;0;2;6,83;10228
19/02/2022;8,9;0;4;8,67;18541
20/02/2022;7,6;0;1;8,17;17248
21/02/2022;6,8;0;2;8;18344
22/02/2022;8;0;1;8,5;17067
23/02/2022;9,3;2;0;7,5;16894
24/02/2022;7,4;0;2;8,5;21641
25/02/2022;6,7;0;2;7,67;21366
26/02/2022;7,4;0;4;9,67;8713
27/02/2022;7,6;0;1;8,33;14112
28/02/2022;6,6;0;5;6,83;14717
01/03/2022;7,2;0;4;6,5;9695
02/03/2022;6,8;0;6;8,67;14628
03/03/2022;7,7;0;2;7;10853
04/03/2022;7,6;0;1;8,5;11261
05/03/2022;9,1;1;0;8,33;18535
06/03/2022;6,9;0;1;8;14473
07/03/2022;6,1;0;7;6,17;13889
08/03/2022;6,6;0;5;6,17;8267
09/03/2022;9,9;6;6;8;12023
10/03/2022;7,5;0;1;5,17;12660
11/03/2022;7,9;0;1;8;12214
12/03/2022;7,3;0;2;7,67;22738
13/03/2022;6,5;0;3;8,67;15916
14/03/2022;8,1;0;3;5,67;14236
15/03/2022;7;0;3;8,17;6253
16/03/2022;6,8;0;4;8,17;16860
17/03/2022;7,4;0;3;9;7670
18/03/2022;7,6;0;2;9,5;15747
19/03/2022;7,8;0;1;8,17;20415
20/03/2022;3,5;-4;8;8,33;27800
21/03/2022;7;0;3;8,67;14077
22/03/2022;7,5;0;3;7,5;12418
23/03/2022;7,7;0;2;7,17;24600
24/03/2022;7,8;0;1;8,83;14366
25/03/2022;8,3;0;0;7;22310
26/03/2022;8,2;0;0;8,33;10295
27/03/2022;8,4;0;0;8,67;14932
28/03/2022;7,9;0;1;7,17;13706
29/03/2022;7,8;0;2;7,5;26041
30/03/2022;6,9;0;3;7;14114
31/03/2022;6,2;0;5;9,5;7275
01/04/2022;6;0;4;8,33;7933
02/04/2022;7;0;4;7,83;17674
03/04/2022;6,7;0;3;9;14618
04/04/2022;6,9;0;3;8,83;20034
05/04/2022;7;0;4;7,83;11736
06/04/2022;7,2;0,5;8;6,5;8778
07/04/2022;6,1;0;6;6,83;12869
08/04/2022;6,9;0;5;8,5;13815
09/04/2022;7,5;0;2;10,03;18324
10/04/2022;8;0;1;7,83;26778
11/04/2022;8,1;0;1;8,52;16248
12/04/2022;10;8;8;7;19224
13/04/2022;9,6;4;0;9;27486
14/04/2022;8,7;0;0;6,83;23752
15/04/2022;8,8;0;0;6,17;29152
16/04/2022;7,8;0;0;7,83;12098
17/04/2022;9,7;4;7;7,83;9395
18/04/2022;8,4;0;1;6,83;9100
19/04/2022;7,9;0;1;10;14101
20/04/2022;7,7;0;4;8,67;7660
21/04/2022;8,5;0;0;7,83;16900
22/04/2022;7,5;0;1;9,17;16360
23/04/2022;6,9;0;4;7,67;17584
24/04/2022;7;0;3;10,5;16151
25/04/2022;6,4;0;5;8,5;16290
26/04/2022;6,1;0;7;8,83;21410
27/04/2022;7,8;0;3;8;18033
28/04/2022;8,3;0;0;9;12182
29/04/2022;6,5;0;4;8,83;7009
30/04/2022;10;95;6;7,17;20985
01/05/2022;8;0;1;9;21802
02/05/2022;8,1;0;0;7,33;21823
03/05/2022;7,6;0;3;9;14889
04/05/2022;10;9;8;7,17;20994
05/05/2022;6,6;0;6;6,67;12451
06/05/2022;8,6;0;4;5,83;31123
07/05/2022;7,9;0;2;8,17;13353
08/05/2022;7,4;0;3;7,83;11877
09/05/2022;8,5;0;0;6,5;17779
10/05/2022;7,8;0;1;8,67;20484
11/05/2022;8,3;0;0;8;24069
12/05/2022;8,4;0;2;7,67;24062
13/05/2022;7,6;0;3;7,5;13996
14/05/2022;9,2;1;0;7,67;16244
15/05/2022;7,7;0;1;7,33;17761
16/05/2022;7,9;0;2;8,67;26477
17/05/2022;8;0;2;8,17;23345
18/05/2022;7,5;0;1;8,67;21089
19/05/2022;7,9;0;2;7,67;20023
20/05/2022;8,7;0;0;6,5;26045
21/05/2022;10;11;0;4,5;31604
22/05/2022;10;14;0;8,33;25639
23/05/2022;10;10;0;8,5;25560
24/05/2022;10;13,5;0;8,5;36900
25/05/2022;10;20;0;8,33;19090
26/05/2022;10;13;0;8,5;21705
27/05/2022;10;13,5;0;8,33;20711
28/05/2022;10;1000;8;6,33;31981
29/05/2022;10;1000;0;5,17;29407
30/05/2022;10;40;1;7;13857
31/05/2022;10;11;0;8,5;29712
01/06/2022;10;18;0;8;21347
02/06/2022;10;17;0;8,17;25869
03/06/2022;10;16,5;0;7;21763
04/06/2022;10;20;0;6,17;19796
05/06/2022;10;15;1;6,33;29642
06/06/2022;7,5;0;2;4,33;8325
07/06/2022;7,4;0;2;8;26394
08/06/2022;6,7;0;3;5,67;14205
09/06/2022;6,9;0;4;9;12284
10/06/2022;7,6;0;1;8,17;16488
11/06/2022;7,5;0;1;8,17;21532
12/06/2022;7,8;0;0;8,83;9212
13/06/2022;7,6;0;1;8,67;12309
14/06/2022;7,9;0;1;7,33;29027
15/06/2022;8,1;0;0;9,33;11426
16/06/2022;8;0;0;8,33;18057
17/06/2022;8,3;0;1;7,33;11779
18/06/2022;8,8;0;1;7,5;16743
19/06/2022;8,9;0;1;6,5;16158
20/06/2022;7,9;0;0;8,67;15383
21/06/2022;7,1;0;3;8,17;14844
22/06/2022;6,8;0;5;8,33;10383
23/06/2022;6,5;0;3;10;9958
24/06/2022;6,6;0;6;7,17;22052
25/06/2022;7,8;0;1;10,65;13397
26/06/2022;7,9;0;2;7,5;20771
27/06/2022;7,3;0;2;10,2;19506
28/06/2022;8,4;0;0;10,77;17119
29/06/2022;8,2;0;0;6,83;15731
30/06/2022;7,5;0;1;11,65;7623
01/07/2022;7,4;0;4;8,33;30423
02/07/2022;7,7;0;1;9,97;9615
03/07/2022;7,9;0;1;8;14124
04/07/2022;7,3;0;2;10,67;18823
05/07/2022;8,7;1;0;8,5;16861
06/07/2022;9,4;3,5;1;8,67;16428
07/07/2022;7,5;0;3;8;12866
08/07/2022;8,2;0;2;8,67;9044
09/07/2022;9;2;1;8,83;14660
10/07/2022;7,1;0;6;8,5;10533
11/07/2022;7,7;0;2;7,33;16711
12/07/2022;7,6;0;2;8,83;9223
13/07/2022;7,4;0;2;8,83;13029
14/07/2022;8,4;0;1;8,33;11351
15/07/2022;7,2;0;4;8;11853
16/07/2022;7,8;0;3;8,43;14537
17/07/2022;6,4;0;7;8,5;9689
18/07/2022;8;0;7;7,5;8110
19/07/2022;8,8;0,5;0;9;16571
20/07/2022;8,3;0;1;8;11135
21/07/2022;6,8;0;8;9,67;8963
22/07/2022;7,9;0;2;9,17;25097
23/07/2022;6,5;0;8;4,67;10898
24/07/2022;8,1;0;1;9,33;13271
25/07/2022;7,6;0;3;8,67;24825
26/07/2022;7,9;0;1;8,5;14022
27/07/2022;9,7;4;0;8,17;13096
28/07/2022;8,3;0;0;7,83;11140
29/07/2022;7,8;0;2;9,33;11624
30/07/2022;6,8;0;5;7,83;17052
31/07/2022;7;0;6;6,67;15164

My code is this
'''notation=read.csv(file.choose(), sep=";", dec=",", header=TRUE)
dftest <- data.frame(notation)
install.packages("tidyr")
library(tidyr)
library(tidyverse)
library(ggplot2)

ggplot(dftest, aes(x=Date, y=Note)) +
geom_point()+
geom_smooth()

The plot works but i don't have the smooth line and there are missing points
task.pdf (20.3 KB)

I think you need to convert your Date variable into a "date" class variable, take a look at this example

library(tidyverse)
library(lubridate)

# Reaing from your sample data, you can read from your csv file instead
dftest <- read.csv(text = "Date;Note;Obs;stress;Sommeil;Activite
01/01/2022;7,5;0;2;7,1;17343
02/01/2022;7,8;0;4;7,67;10494
03/01/2022;6,5;0;6;6,45;9349
04/01/2022;6,7;0;4;9,83;6201
05/01/2022;7,7;0;6;7,5;6294
06/01/2022;7;0;3;8,33;7092
07/01/2022;7,2;0;2;6,32;8653
08/01/2022;8,3;0;4;9,33;16374
09/01/2022;6,6;0;1;8,17;15055
10/01/2022;6,2;0;5;6,83;9550
11/01/2022;7,7;0;1;9,17;10449
12/01/2022;9,8;5;8;8;11351
13/01/2022;7;0;3;7,17;9002
14/01/2022;6,9;0;4;9;9768
15/01/2022;6,3;0;6;7,15;15711
16/01/2022;10;7;5;9,33;14341
17/01/2022;6,4;0;6;6,33;7827
18/01/2022;6,9;0;4;7;9522
19/01/2022;7;0;6;8,5;6499
20/01/2022;9;1;6;7,17;10250
21/01/2022;7,1;0;2;6,33;15114
22/01/2022;7,2;0;3;9,5;18985
23/01/2022;7,1;0;7;0,5;40168
24/01/2022;5,8;0;8;6,67;9115
25/01/2022;7,5;0;3;6,33;9398
26/01/2022;6,6;0;3;7,5;9784
27/01/2022;6,8;0;2;7;9690
28/01/2022;7,8;0;3;10;9271
29/01/2022;7;0;2;9,33;15901
30/01/2022;7,1;0;2;7,07;19450
31/01/2022;7,5;0;2;6,5;9453
01/02/2022;6,9;0;6;6,83;9085
02/02/2022;6,5;0;4;8,33;11044
03/02/2022;5,2;-1;7;7,17;8432
04/02/2022;7;0;2;9,33;10259
05/02/2022;6,8;0;1;9,33;13672
06/02/2022;7,3;0;3;10;16965
07/02/2022;6;0;6;6;7475
08/02/2022;7,5;0;5;6,5;9404
09/02/2022;8,4;0;0;8,67;12155
10/02/2022;6,4;0;4;7,33;7413
11/02/2022;6,5;0;6;9,5;6326
12/02/2022;6,6;0;4;8,5;14953
13/02/2022;7,7;0;2;7,67;20149
14/02/2022;6,4;0;4;8,67;11936
15/02/2022;5,4;-1;7;8,67;12722
16/02/2022;6,2;0;5;7,33;16582
17/02/2022;8,2;0;3;9,5;16556
18/02/2022;8,3;0;2;6,83;10228
19/02/2022;8,9;0;4;8,67;18541
20/02/2022;7,6;0;1;8,17;17248
21/02/2022;6,8;0;2;8;18344
22/02/2022;8;0;1;8,5;17067
23/02/2022;9,3;2;0;7,5;16894
24/02/2022;7,4;0;2;8,5;21641
25/02/2022;6,7;0;2;7,67;21366
26/02/2022;7,4;0;4;9,67;8713
27/02/2022;7,6;0;1;8,33;14112
28/02/2022;6,6;0;5;6,83;14717
01/03/2022;7,2;0;4;6,5;9695
02/03/2022;6,8;0;6;8,67;14628
03/03/2022;7,7;0;2;7;10853
04/03/2022;7,6;0;1;8,5;11261
05/03/2022;9,1;1;0;8,33;18535
06/03/2022;6,9;0;1;8;14473
07/03/2022;6,1;0;7;6,17;13889
08/03/2022;6,6;0;5;6,17;8267
09/03/2022;9,9;6;6;8;12023
10/03/2022;7,5;0;1;5,17;12660
11/03/2022;7,9;0;1;8;12214
12/03/2022;7,3;0;2;7,67;22738
13/03/2022;6,5;0;3;8,67;15916
14/03/2022;8,1;0;3;5,67;14236
15/03/2022;7;0;3;8,17;6253
16/03/2022;6,8;0;4;8,17;16860
17/03/2022;7,4;0;3;9;7670
18/03/2022;7,6;0;2;9,5;15747
19/03/2022;7,8;0;1;8,17;20415
20/03/2022;3,5;-4;8;8,33;27800
21/03/2022;7;0;3;8,67;14077
22/03/2022;7,5;0;3;7,5;12418
23/03/2022;7,7;0;2;7,17;24600
24/03/2022;7,8;0;1;8,83;14366
25/03/2022;8,3;0;0;7;22310
26/03/2022;8,2;0;0;8,33;10295
27/03/2022;8,4;0;0;8,67;14932
28/03/2022;7,9;0;1;7,17;13706
29/03/2022;7,8;0;2;7,5;26041
30/03/2022;6,9;0;3;7;14114
31/03/2022;6,2;0;5;9,5;7275
01/04/2022;6;0;4;8,33;7933
02/04/2022;7;0;4;7,83;17674
03/04/2022;6,7;0;3;9;14618
04/04/2022;6,9;0;3;8,83;20034
05/04/2022;7;0;4;7,83;11736
06/04/2022;7,2;0,5;8;6,5;8778
07/04/2022;6,1;0;6;6,83;12869
08/04/2022;6,9;0;5;8,5;13815
09/04/2022;7,5;0;2;10,03;18324
10/04/2022;8;0;1;7,83;26778
11/04/2022;8,1;0;1;8,52;16248
12/04/2022;10;8;8;7;19224
13/04/2022;9,6;4;0;9;27486
14/04/2022;8,7;0;0;6,83;23752
15/04/2022;8,8;0;0;6,17;29152
16/04/2022;7,8;0;0;7,83;12098
17/04/2022;9,7;4;7;7,83;9395
18/04/2022;8,4;0;1;6,83;9100
19/04/2022;7,9;0;1;10;14101
20/04/2022;7,7;0;4;8,67;7660
21/04/2022;8,5;0;0;7,83;16900
22/04/2022;7,5;0;1;9,17;16360
23/04/2022;6,9;0;4;7,67;17584
24/04/2022;7;0;3;10,5;16151
25/04/2022;6,4;0;5;8,5;16290
26/04/2022;6,1;0;7;8,83;21410
27/04/2022;7,8;0;3;8;18033
28/04/2022;8,3;0;0;9;12182
29/04/2022;6,5;0;4;8,83;7009
30/04/2022;10;95;6;7,17;20985
01/05/2022;8;0;1;9;21802
02/05/2022;8,1;0;0;7,33;21823
03/05/2022;7,6;0;3;9;14889
04/05/2022;10;9;8;7,17;20994
05/05/2022;6,6;0;6;6,67;12451
06/05/2022;8,6;0;4;5,83;31123
07/05/2022;7,9;0;2;8,17;13353
08/05/2022;7,4;0;3;7,83;11877
09/05/2022;8,5;0;0;6,5;17779
10/05/2022;7,8;0;1;8,67;20484
11/05/2022;8,3;0;0;8;24069
12/05/2022;8,4;0;2;7,67;24062
13/05/2022;7,6;0;3;7,5;13996
14/05/2022;9,2;1;0;7,67;16244
15/05/2022;7,7;0;1;7,33;17761
16/05/2022;7,9;0;2;8,67;26477
17/05/2022;8;0;2;8,17;23345
18/05/2022;7,5;0;1;8,67;21089
19/05/2022;7,9;0;2;7,67;20023
20/05/2022;8,7;0;0;6,5;26045
21/05/2022;10;11;0;4,5;31604
22/05/2022;10;14;0;8,33;25639
23/05/2022;10;10;0;8,5;25560
24/05/2022;10;13,5;0;8,5;36900
25/05/2022;10;20;0;8,33;19090
26/05/2022;10;13;0;8,5;21705
27/05/2022;10;13,5;0;8,33;20711
28/05/2022;10;1000;8;6,33;31981
29/05/2022;10;1000;0;5,17;29407
30/05/2022;10;40;1;7;13857
31/05/2022;10;11;0;8,5;29712
01/06/2022;10;18;0;8;21347
02/06/2022;10;17;0;8,17;25869
03/06/2022;10;16,5;0;7;21763
04/06/2022;10;20;0;6,17;19796
05/06/2022;10;15;1;6,33;29642
06/06/2022;7,5;0;2;4,33;8325
07/06/2022;7,4;0;2;8;26394
08/06/2022;6,7;0;3;5,67;14205
09/06/2022;6,9;0;4;9;12284
10/06/2022;7,6;0;1;8,17;16488
11/06/2022;7,5;0;1;8,17;21532
12/06/2022;7,8;0;0;8,83;9212
13/06/2022;7,6;0;1;8,67;12309
14/06/2022;7,9;0;1;7,33;29027
15/06/2022;8,1;0;0;9,33;11426
16/06/2022;8;0;0;8,33;18057
17/06/2022;8,3;0;1;7,33;11779
18/06/2022;8,8;0;1;7,5;16743
19/06/2022;8,9;0;1;6,5;16158
20/06/2022;7,9;0;0;8,67;15383
21/06/2022;7,1;0;3;8,17;14844
22/06/2022;6,8;0;5;8,33;10383
23/06/2022;6,5;0;3;10;9958
24/06/2022;6,6;0;6;7,17;22052
25/06/2022;7,8;0;1;10,65;13397
26/06/2022;7,9;0;2;7,5;20771
27/06/2022;7,3;0;2;10,2;19506
28/06/2022;8,4;0;0;10,77;17119
29/06/2022;8,2;0;0;6,83;15731
30/06/2022;7,5;0;1;11,65;7623
01/07/2022;7,4;0;4;8,33;30423
02/07/2022;7,7;0;1;9,97;9615
03/07/2022;7,9;0;1;8;14124
04/07/2022;7,3;0;2;10,67;18823
05/07/2022;8,7;1;0;8,5;16861
06/07/2022;9,4;3,5;1;8,67;16428
07/07/2022;7,5;0;3;8;12866
08/07/2022;8,2;0;2;8,67;9044
09/07/2022;9;2;1;8,83;14660
10/07/2022;7,1;0;6;8,5;10533
11/07/2022;7,7;0;2;7,33;16711
12/07/2022;7,6;0;2;8,83;9223
13/07/2022;7,4;0;2;8,83;13029
14/07/2022;8,4;0;1;8,33;11351
15/07/2022;7,2;0;4;8;11853
16/07/2022;7,8;0;3;8,43;14537
17/07/2022;6,4;0;7;8,5;9689
18/07/2022;8;0;7;7,5;8110
19/07/2022;8,8;0,5;0;9;16571
20/07/2022;8,3;0;1;8;11135
21/07/2022;6,8;0;8;9,67;8963
22/07/2022;7,9;0;2;9,17;25097
23/07/2022;6,5;0;8;4,67;10898
24/07/2022;8,1;0;1;9,33;13271
25/07/2022;7,6;0;3;8,67;24825
26/07/2022;7,9;0;1;8,5;14022
27/07/2022;9,7;4;0;8,17;13096
28/07/2022;8,3;0;0;7,83;11140
29/07/2022;7,8;0;2;9,33;11624
30/07/2022;6,8;0;5;7,83;17052
31/07/2022;7;0;6;6,67;15164", sep = ";", dec = ",", header = TRUE)

dftest %>% 
    mutate(Date = dmy(Date)) %>% 
    ggplot(aes(x = Date, y = Note)) +
    geom_point() +
    geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2022-08-05 by the reprex package (v2.0.1)

1 Like

Everything works, thanks you !
My final question is this : how to make the density for each mounth with the last data ?

Is this what you mean?

library(tidyverse)
library(lubridate)

# Reaing from your sample data, you can read from your csv file instead
dftest <- read.csv(text = "Date;Note;Obs;stress;Sommeil;Activite
01/01/2022;7,5;0;2;7,1;17343
02/01/2022;7,8;0;4;7,67;10494
03/01/2022;6,5;0;6;6,45;9349
04/01/2022;6,7;0;4;9,83;6201
05/01/2022;7,7;0;6;7,5;6294
06/01/2022;7;0;3;8,33;7092
07/01/2022;7,2;0;2;6,32;8653
08/01/2022;8,3;0;4;9,33;16374
09/01/2022;6,6;0;1;8,17;15055
10/01/2022;6,2;0;5;6,83;9550
11/01/2022;7,7;0;1;9,17;10449
12/01/2022;9,8;5;8;8;11351
13/01/2022;7;0;3;7,17;9002
14/01/2022;6,9;0;4;9;9768
15/01/2022;6,3;0;6;7,15;15711
16/01/2022;10;7;5;9,33;14341
17/01/2022;6,4;0;6;6,33;7827
18/01/2022;6,9;0;4;7;9522
19/01/2022;7;0;6;8,5;6499
20/01/2022;9;1;6;7,17;10250
21/01/2022;7,1;0;2;6,33;15114
22/01/2022;7,2;0;3;9,5;18985
23/01/2022;7,1;0;7;0,5;40168
24/01/2022;5,8;0;8;6,67;9115
25/01/2022;7,5;0;3;6,33;9398
26/01/2022;6,6;0;3;7,5;9784
27/01/2022;6,8;0;2;7;9690
28/01/2022;7,8;0;3;10;9271
29/01/2022;7;0;2;9,33;15901
30/01/2022;7,1;0;2;7,07;19450
31/01/2022;7,5;0;2;6,5;9453
01/02/2022;6,9;0;6;6,83;9085
02/02/2022;6,5;0;4;8,33;11044
03/02/2022;5,2;-1;7;7,17;8432
04/02/2022;7;0;2;9,33;10259
05/02/2022;6,8;0;1;9,33;13672
06/02/2022;7,3;0;3;10;16965
07/02/2022;6;0;6;6;7475
08/02/2022;7,5;0;5;6,5;9404
09/02/2022;8,4;0;0;8,67;12155
10/02/2022;6,4;0;4;7,33;7413
11/02/2022;6,5;0;6;9,5;6326
12/02/2022;6,6;0;4;8,5;14953
13/02/2022;7,7;0;2;7,67;20149
14/02/2022;6,4;0;4;8,67;11936
15/02/2022;5,4;-1;7;8,67;12722
16/02/2022;6,2;0;5;7,33;16582
17/02/2022;8,2;0;3;9,5;16556
18/02/2022;8,3;0;2;6,83;10228
19/02/2022;8,9;0;4;8,67;18541
20/02/2022;7,6;0;1;8,17;17248
21/02/2022;6,8;0;2;8;18344
22/02/2022;8;0;1;8,5;17067
23/02/2022;9,3;2;0;7,5;16894
24/02/2022;7,4;0;2;8,5;21641
25/02/2022;6,7;0;2;7,67;21366
26/02/2022;7,4;0;4;9,67;8713
27/02/2022;7,6;0;1;8,33;14112
28/02/2022;6,6;0;5;6,83;14717
01/03/2022;7,2;0;4;6,5;9695
02/03/2022;6,8;0;6;8,67;14628
03/03/2022;7,7;0;2;7;10853
04/03/2022;7,6;0;1;8,5;11261
05/03/2022;9,1;1;0;8,33;18535
06/03/2022;6,9;0;1;8;14473
07/03/2022;6,1;0;7;6,17;13889
08/03/2022;6,6;0;5;6,17;8267
09/03/2022;9,9;6;6;8;12023
10/03/2022;7,5;0;1;5,17;12660
11/03/2022;7,9;0;1;8;12214
12/03/2022;7,3;0;2;7,67;22738
13/03/2022;6,5;0;3;8,67;15916
14/03/2022;8,1;0;3;5,67;14236
15/03/2022;7;0;3;8,17;6253
16/03/2022;6,8;0;4;8,17;16860
17/03/2022;7,4;0;3;9;7670
18/03/2022;7,6;0;2;9,5;15747
19/03/2022;7,8;0;1;8,17;20415
20/03/2022;3,5;-4;8;8,33;27800
21/03/2022;7;0;3;8,67;14077
22/03/2022;7,5;0;3;7,5;12418
23/03/2022;7,7;0;2;7,17;24600
24/03/2022;7,8;0;1;8,83;14366
25/03/2022;8,3;0;0;7;22310
26/03/2022;8,2;0;0;8,33;10295
27/03/2022;8,4;0;0;8,67;14932
28/03/2022;7,9;0;1;7,17;13706
29/03/2022;7,8;0;2;7,5;26041
30/03/2022;6,9;0;3;7;14114
31/03/2022;6,2;0;5;9,5;7275
01/04/2022;6;0;4;8,33;7933
02/04/2022;7;0;4;7,83;17674
03/04/2022;6,7;0;3;9;14618
04/04/2022;6,9;0;3;8,83;20034
05/04/2022;7;0;4;7,83;11736
06/04/2022;7,2;0,5;8;6,5;8778
07/04/2022;6,1;0;6;6,83;12869
08/04/2022;6,9;0;5;8,5;13815
09/04/2022;7,5;0;2;10,03;18324
10/04/2022;8;0;1;7,83;26778
11/04/2022;8,1;0;1;8,52;16248
12/04/2022;10;8;8;7;19224
13/04/2022;9,6;4;0;9;27486
14/04/2022;8,7;0;0;6,83;23752
15/04/2022;8,8;0;0;6,17;29152
16/04/2022;7,8;0;0;7,83;12098
17/04/2022;9,7;4;7;7,83;9395
18/04/2022;8,4;0;1;6,83;9100
19/04/2022;7,9;0;1;10;14101
20/04/2022;7,7;0;4;8,67;7660
21/04/2022;8,5;0;0;7,83;16900
22/04/2022;7,5;0;1;9,17;16360
23/04/2022;6,9;0;4;7,67;17584
24/04/2022;7;0;3;10,5;16151
25/04/2022;6,4;0;5;8,5;16290
26/04/2022;6,1;0;7;8,83;21410
27/04/2022;7,8;0;3;8;18033
28/04/2022;8,3;0;0;9;12182
29/04/2022;6,5;0;4;8,83;7009
30/04/2022;10;95;6;7,17;20985
01/05/2022;8;0;1;9;21802
02/05/2022;8,1;0;0;7,33;21823
03/05/2022;7,6;0;3;9;14889
04/05/2022;10;9;8;7,17;20994
05/05/2022;6,6;0;6;6,67;12451
06/05/2022;8,6;0;4;5,83;31123
07/05/2022;7,9;0;2;8,17;13353
08/05/2022;7,4;0;3;7,83;11877
09/05/2022;8,5;0;0;6,5;17779
10/05/2022;7,8;0;1;8,67;20484
11/05/2022;8,3;0;0;8;24069
12/05/2022;8,4;0;2;7,67;24062
13/05/2022;7,6;0;3;7,5;13996
14/05/2022;9,2;1;0;7,67;16244
15/05/2022;7,7;0;1;7,33;17761
16/05/2022;7,9;0;2;8,67;26477
17/05/2022;8;0;2;8,17;23345
18/05/2022;7,5;0;1;8,67;21089
19/05/2022;7,9;0;2;7,67;20023
20/05/2022;8,7;0;0;6,5;26045
21/05/2022;10;11;0;4,5;31604
22/05/2022;10;14;0;8,33;25639
23/05/2022;10;10;0;8,5;25560
24/05/2022;10;13,5;0;8,5;36900
25/05/2022;10;20;0;8,33;19090
26/05/2022;10;13;0;8,5;21705
27/05/2022;10;13,5;0;8,33;20711
28/05/2022;10;1000;8;6,33;31981
29/05/2022;10;1000;0;5,17;29407
30/05/2022;10;40;1;7;13857
31/05/2022;10;11;0;8,5;29712
01/06/2022;10;18;0;8;21347
02/06/2022;10;17;0;8,17;25869
03/06/2022;10;16,5;0;7;21763
04/06/2022;10;20;0;6,17;19796
05/06/2022;10;15;1;6,33;29642
06/06/2022;7,5;0;2;4,33;8325
07/06/2022;7,4;0;2;8;26394
08/06/2022;6,7;0;3;5,67;14205
09/06/2022;6,9;0;4;9;12284
10/06/2022;7,6;0;1;8,17;16488
11/06/2022;7,5;0;1;8,17;21532
12/06/2022;7,8;0;0;8,83;9212
13/06/2022;7,6;0;1;8,67;12309
14/06/2022;7,9;0;1;7,33;29027
15/06/2022;8,1;0;0;9,33;11426
16/06/2022;8;0;0;8,33;18057
17/06/2022;8,3;0;1;7,33;11779
18/06/2022;8,8;0;1;7,5;16743
19/06/2022;8,9;0;1;6,5;16158
20/06/2022;7,9;0;0;8,67;15383
21/06/2022;7,1;0;3;8,17;14844
22/06/2022;6,8;0;5;8,33;10383
23/06/2022;6,5;0;3;10;9958
24/06/2022;6,6;0;6;7,17;22052
25/06/2022;7,8;0;1;10,65;13397
26/06/2022;7,9;0;2;7,5;20771
27/06/2022;7,3;0;2;10,2;19506
28/06/2022;8,4;0;0;10,77;17119
29/06/2022;8,2;0;0;6,83;15731
30/06/2022;7,5;0;1;11,65;7623
01/07/2022;7,4;0;4;8,33;30423
02/07/2022;7,7;0;1;9,97;9615
03/07/2022;7,9;0;1;8;14124
04/07/2022;7,3;0;2;10,67;18823
05/07/2022;8,7;1;0;8,5;16861
06/07/2022;9,4;3,5;1;8,67;16428
07/07/2022;7,5;0;3;8;12866
08/07/2022;8,2;0;2;8,67;9044
09/07/2022;9;2;1;8,83;14660
10/07/2022;7,1;0;6;8,5;10533
11/07/2022;7,7;0;2;7,33;16711
12/07/2022;7,6;0;2;8,83;9223
13/07/2022;7,4;0;2;8,83;13029
14/07/2022;8,4;0;1;8,33;11351
15/07/2022;7,2;0;4;8;11853
16/07/2022;7,8;0;3;8,43;14537
17/07/2022;6,4;0;7;8,5;9689
18/07/2022;8;0;7;7,5;8110
19/07/2022;8,8;0,5;0;9;16571
20/07/2022;8,3;0;1;8;11135
21/07/2022;6,8;0;8;9,67;8963
22/07/2022;7,9;0;2;9,17;25097
23/07/2022;6,5;0;8;4,67;10898
24/07/2022;8,1;0;1;9,33;13271
25/07/2022;7,6;0;3;8,67;24825
26/07/2022;7,9;0;1;8,5;14022
27/07/2022;9,7;4;0;8,17;13096
28/07/2022;8,3;0;0;7,83;11140
29/07/2022;7,8;0;2;9,33;11624
30/07/2022;6,8;0;5;7,83;17052
31/07/2022;7;0;6;6,67;15164", sep = ";", dec = ",", header = TRUE)

dftest %>% 
    mutate(Date = dmy(Date),
           Month = month(Date, label = TRUE)) %>% 
    ggplot(aes(x = Date, y = Note, color = Month)) +
    geom_point() +
    geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2022-08-05 by the reprex package (v2.0.1)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.