hello and welcome back
in this
we'll go over USA
Map
with COVID data
so we will start by preparing the data to make a map
And then we'll also make use of
longitude and latitude data
and merge the data with the COVID data that we have
Finally we'll create geographic map
representing number of cases in each state
in USA
Let's read COVID data in c
it's a CSV file
And it has header in the first row
Let's say true
so you can see 'c' has 117,771
observations with 34
columns so it includes ID of each
patient age group
sex, city, province, country and so on
one of the columns is country so i am going to filter
this data and only focus on united states
so we connect c to filter
and say country is united states
so this is what we have now so we have all
the states within Us let's find out
how many cases are there in each state
we'll store that information in USA it self
so let's group by
in this data set
states are called province
and then connect this to summarize
where we'll store within count no. of
case we can also arrange
every thing in descending order for count
so if you look at usa we have
all the states and we have count for
each state based on the data when this was collected
New York was at top
with 4000+ cases
we have data on COVID for each state
we also have data on latitude and longitude for each
state so we need to merge
that information is you look at as
we have this column called region for
states and every thing is lower case
but in USA states are named as
province and you will see the first word
starts with the upper case first of all we have to
make sure that both are lower case
so lets use USA dollar sign province
and say true lower
so now if you look at USA you will see everything is
lower case
so now we can merge data
and let's draw this merge data in data
so first dataset that we have
is in 's' and second one is in USA
So you can think of the first one is x and
second one as 'y' and when we merge
we have to make sure that the column in 's'
matches with USA
so this column is called region here
so in s you can see states are regions
and for the second file USA it's
called province
so if we look at data we'll
now see that we have states longitude
latitude as well as counts
so now we can create a map
se we will use ggplot and the data
is data
so for fill we can use count
and then we can add next layer
polygon and then if you run this
so it will give a US map which
is a default one but we can make some improvements
For example between the states we can add
some color
we can also use the coordinate_map
polyconic so that it doesn't look stretched
or compressed
so this is slidely better but if you look at the color
it goes from light to dark
in the opposite direction we have to fix that
so let's use scale_fill_gradient
we can also try 2
so darker color is for New York and california and other states where
the numbers are high
and lighter colors are for other states
obviously this is much better
if you want to use a specific color you could do
low equals let's say white
high equals w can try red
so if you do not like the background you can get rid of that
theme_white
can also add a title
so this gives us a cleaner background
in the next video we will look at USA map
for each county