-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotCoronaData.m
82 lines (66 loc) · 2.06 KB
/
plotCoronaData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function [] = plotCoronaData(timeVector,mergedData,chosenCountries,type)
%% This function plots a subset of countries.
%
% Input (from processCoronaData.m):
% timeVector: Time/date vector
% mergedData: Cases per country
% chosenCountries (optional): Countries in a cell array
%
% Output:
% none
%
% Example: plotCoronaData(timeVector,mergedData,{'Italy','Germany','Denmark'})
%
% 19th of March 2020: Axel Ahrens, Technical University of Denmark
%% check for input parameters
if nargin < 4
type = 'Confirmed';
elseif nargin < 3
chosenCountries = {'Germany','Denmark','Italy','China','US'};
type = 'Confirmed';
end
%% check for right data types/capitalization
if ~(strcmpi(type,'confirmed') || strcmpi(type,'deaths') || strcmpi(type,'recovered'))
warning('This type does not exist. Please choose either Confirmed, Deaths, or Recovered.')
end
type = lower(type);
%% choose countries
if sum(strcmp(chosenCountries,'all')) || sum(strcmp(chosenCountries{1},'all'))
rowNums = 1:size(mergedData,1);
else
for n = 1:length(chosenCountries)
rowNums(n) = find(contains(mergedData(:,1),chosenCountries{n}));
end
end
dataMatrix = cell2mat(mergedData(rowNums,2));
%% plotting abs number
figure,
ax = gca;
plot(timeVector,dataMatrix)
if strcmpi(type,'confirmed')
ylabel('#confirmed cases')
elseif strcmpi(type,'deaths')
ylabel('#deaths')
elseif strcmpi(type,'recovered')
ylabel('#recovered')
else
warning('Unknown type. Cannot annotate plot.')
end
text(repmat(timeVector(end),[size(dataMatrix,1) 1]),dataMatrix(:,end),mergedData(rowNums,1))
ax.FontSize = 16;
%% plotting change
casesPerDay = diff(dataMatrix,1,2);
figure,
ax = gca;
plot(timeVector(2:end),casesPerDay)
if strcmpi(type,'confirmed')
ylabel('increase #confirmed cases per day')
elseif strcmpi(type,'deaths')
ylabel('increase #deaths per day')
elseif strcmpi(type,'recovered')
ylabel('increase #recovered per day')
else
warning('Unknown type. Cannot annotate plot.')
end
text(repmat(timeVector(end),[size(dataMatrix,1) 1]),casesPerDay(:,end),mergedData(rowNums,1))
ax.FontSize = 16;