How to convert to a time series and plot a dataframe with each day as a variable or column?

Antoni Parellada

I am trying to get a plot of the number of Cov-19 in Italy over time, and came across this repository in GitHub, and tried to subset the data for Italy as such:

require(RCurl)
require(foreign)
x = getURL("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
corona = read.csv(text = x, sep =",",header = T)
str(corona)
Italy <- corona[,corona$Country.Region=='Italy']
Italy <- corona[corona$Country.Region=='Italy',][1,5:ncol(corona)]
head(Italy)[,45:52]

which outputs:

> head(Italy)[,45:52]
   X3.6.20 X3.7.20 X3.8.20 X3.9.20 X3.10.20 X3.11.20 X3.12.20
17    4636    5883    7375    9172    10149    12462    12462
   X3.13.20
17    17660

Converting this to a time series with xts led me to several posts asking how to convert a database to a time series, where every day is a row in the variable Date, but in this dataframe it seems as though the each date is a variable.

I don't necessarily need to get this formatted as a time series, but I would like to plot over time the number of cases.


Here is a way to bypass timeseries:

require(RCurl)
require(foreign)
x = getURL("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
corona = read.csv(text = x, sep =",",header = T)
str(corona)
Italy <- corona[,corona$Country.Region=='Italy']
Italy <- corona[corona$Country.Region=='Italy',][1,5:ncol(corona)]
Italy <- as.matrix(sapply(Italy, as.numeric))
plot(Italy[,1],typ='l',xlab='', ylab='', col='red', lwd=3,
     main="Italy Cov-19 cum cases")
akrun

We can convert to xts and plot

library(xts)
plot(xts(unlist(Italy), order.by = as.Date(sub("X", "", names(Italy)),
        "%m.%d.%y")), , main = "xts plot")

enter image description here


Some values are 0, so converting those to NA as it can lead to Inf values when the log2 conversion is done

library(dplyr)
plot(xts(log(na_if(unlist(Italy), 0), 2), order.by = as.Date(sub("X", "", names(Italy)),
     "%m.%d.%y")), main = 'xts log2 plot')

enter image description here

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to convert to a time series and plot a dataframe with each day as a variable or column?

分類Dev

How to plot beautifully the segmentation of time series (pandas dataframe)

分類Dev

Pandas - How to repeat dataframe n times each time adding a column

分類Dev

Pandas dataframe plot regressions curves for each column

分類Dev

How to plot a scatter plot using a pandas dataframe where the x-axis values are n minus 1 columns and the last column is the dependent variable?

分類Dev

How to remove inconsistencies from dataframe (time series)

分類Dev

Plot time series on category level

分類Dev

R: How to get the maximum value of a datetime column in a time series data

分類Dev

DataFrame.apply with str.extract throws error even though function works on each column-series

分類Dev

R studio: Decompose / pivot a dataframe to calculate the mean value for each variable at various time segments for each group

分類Dev

Pandas convert Column to time

分類Dev

python pandas time series select day of year

分類Dev

Time operations on a dataframe column

分類Dev

pandas groupby how to aggregate on a column and convert to a matrix that each cell is a dictionary

分類Dev

How can I plot specific attributes rather than default of all attributes in Time Series

分類Dev

How to plot multiple time series with a reverse barplot on the secondary axis using ggplot2?

分類Dev

How to decile python pandas dataframe by column value, and then sum each decile?

分類Dev

How to count the values corresponding to each unique value in another column in a dataframe?

分類Dev

merging time series datasets, but missing the time series column

分類Dev

merging time series datasets, but missing the time series column

分類Dev

How to convert efficiently a dataframe column of string type into datetime in Python?

分類Dev

Convert all rows of a padas dataframe column to comma separated values with each value in single quote

分類Dev

How to convert variable to time format when values have different formatting

分類Dev

How Can I Automatically Separate Time Series Data Based on Set Interval and Summarize Each Subset?

分類Dev

Convert time series data to features - panda way?

分類Dev

spark dataframe trim column and convert

分類Dev

upsampling multiple time series in one dataframe

分類Dev

Expand time series data in pandas dataframe

分類Dev

format a time series as dataframe with julian date

Related 関連記事

  1. 1

    How to convert to a time series and plot a dataframe with each day as a variable or column?

  2. 2

    How to plot beautifully the segmentation of time series (pandas dataframe)

  3. 3

    Pandas - How to repeat dataframe n times each time adding a column

  4. 4

    Pandas dataframe plot regressions curves for each column

  5. 5

    How to plot a scatter plot using a pandas dataframe where the x-axis values are n minus 1 columns and the last column is the dependent variable?

  6. 6

    How to remove inconsistencies from dataframe (time series)

  7. 7

    Plot time series on category level

  8. 8

    R: How to get the maximum value of a datetime column in a time series data

  9. 9

    DataFrame.apply with str.extract throws error even though function works on each column-series

  10. 10

    R studio: Decompose / pivot a dataframe to calculate the mean value for each variable at various time segments for each group

  11. 11

    Pandas convert Column to time

  12. 12

    python pandas time series select day of year

  13. 13

    Time operations on a dataframe column

  14. 14

    pandas groupby how to aggregate on a column and convert to a matrix that each cell is a dictionary

  15. 15

    How can I plot specific attributes rather than default of all attributes in Time Series

  16. 16

    How to plot multiple time series with a reverse barplot on the secondary axis using ggplot2?

  17. 17

    How to decile python pandas dataframe by column value, and then sum each decile?

  18. 18

    How to count the values corresponding to each unique value in another column in a dataframe?

  19. 19

    merging time series datasets, but missing the time series column

  20. 20

    merging time series datasets, but missing the time series column

  21. 21

    How to convert efficiently a dataframe column of string type into datetime in Python?

  22. 22

    Convert all rows of a padas dataframe column to comma separated values with each value in single quote

  23. 23

    How to convert variable to time format when values have different formatting

  24. 24

    How Can I Automatically Separate Time Series Data Based on Set Interval and Summarize Each Subset?

  25. 25

    Convert time series data to features - panda way?

  26. 26

    spark dataframe trim column and convert

  27. 27

    upsampling multiple time series in one dataframe

  28. 28

    Expand time series data in pandas dataframe

  29. 29

    format a time series as dataframe with julian date

ホットタグ

アーカイブ