Jim Lemon
2018-Dec-18 01:56 UTC
[R] [R studio] Plotting of line chart for each columns at 1 page
Hi Subhamitra, As for the error that you mention, it was probably: Error in axis(1, at = year_mids, labels = 3 - 1 - 1994:3 - 8 - 2017) : 'at' and 'labels' lengths differ, 24 != 1992 Anything more than a passing glance reveals that you didn't read the explanation I sent about the arguments passed to the "axis" function. Perhaps it will be rewarding to read the help page for the "axis" function in the "graphics" package. Your confusion about the logic (really simple arithmetic) of assigning positions for the year labels may be allayed by the following. Think back to those grade school problems that read: "If I have m apples to give to n people, how many must I give each person so that all will receive the same number and I will have the fewest apples left?" I'm sure that you remember that this can be solved in a number of ways. You can divide m/n and drop the remainder. So, from 03-01-2002 to 03-08-2017 in EMs2.1: diff(as.Date(c("03-01-2002","03-08-2017"),"%d-%m-%Y")) Time difference of 5691 days # plus 1 for all of the days included # calculate the number of years 5692/365.25 [1] 15.58385 So if there had been an observation each day, you would have the trivial task of dividing the number of days by the number of years to get the tick increments: 5692/15.58385 365.2499 Of course you don't have that many observations and you are trying to get the number of observations, not days, in each year. By making the assumption that the missing observations are spread evenly over the years, you can simply replace the number of days with the number of observations. At the moment I don't have that as I unrared your data at home. But you do have it and I will call it nobs: # this calculates the number of observations per year nobs/15.58385 <obs_per_year> will yield the number of observations in each year. So you have your tick increments. Now for the offset. If you want the year ticks to appear at the middle of each year, you will want to start at 182 minus the two days missing in January or 180. So your new year_mids will be: year_mids<-seq(180,nobs,obs_per_year) Your years are 2002:2017 for EMs2.1, so: axis(1,year_mids,2002:2017) may well be what you want for axis ticks. As you can see, the "m apples to n people" approach gives you the answer. The only missing part was the offset, or where to start handing out apples. You might want to have another look at the help pages for "axis" and "seq" (or ":") which will show you why your axis command failed badly. Good luck. Jim On Mon, Dec 17, 2018 at 6:12 PM Subhamitra Patra <subhamitra.patra at gmail.com> wrote:> Hello Sir, > > Thank you very much for your excellent guidance to a new R learner. > > I tried with your suggested code and got the expected results, but for the > 2 CSV files (i.e. EMs2.1. and EMs.3.1), the date column is not coming in > the X-axis (shown in the last row of the attached result Pdf file). I > think I need to increase more or less than 229 in the year-mids because for > both the CSV files, starting date is 03-01-2002 and 04-07-2001 > (date-month-year) for EMs 2.1. and EMs 3.1. respectively. *Sir, hence I > am quite confused for the logic behind the fixing of year_mids*. For your > convenience, I am attaching both the code and result file. >[[alternative HTML version deleted]]
Jim Lemon
2018-Dec-18 10:01 UTC
[R] [R studio] Plotting of line chart for each columns at 1 page
Hi Subhamitra, My apologies, I caught a mistake. To have the first tick in the middle of the first year, you want half of the _observations_ in a year, not half of the days. As I now have your data at my fingertips: 3567/15.58385 [1] 228.8908 Almost exactly what was calculated for the first series. Your increment remains 229 and your offset is 114, so year_mids<-seq(114,3567,229) Jim [[alternative HTML version deleted]]
Subhamitra Patra
2018-Dec-18 12:26 UTC
[R] [R studio] Plotting of line chart for each columns at 1 page
Hello Sir, It is really great learning for me while discussing with you. As per your suggestion, I also read the axis function in the graphics package, and now completely understand your logic. I will apply the same logic for my rest variable and would like to discuss after the successful generation of all plots. Thank you very much, Sir, for pointing me to the right path. [image: Mailtrack] <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&> Sender notified by Mailtrack <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&> 12/18/18, 5:54:53 PM On Tue, Dec 18, 2018 at 3:31 PM Jim Lemon <drjimlemon at gmail.com> wrote:> Hi Subhamitra, > My apologies, I caught a mistake. To have the first tick in the middle of > the first year, you want half of the _observations_ in a year, not half of > the days. As I now have your data at my fingertips: > > 3567/15.58385 > [1] 228.8908 > > Almost exactly what was calculated for the first series. Your increment > remains 229 and your offset is 114, so > > year_mids<-seq(114,3567,229) > > Jim > >-- *Best Regards,* *Subhamitra Patra* *Phd. Research Scholar* *Department of Humanities and Social Sciences* *Indian Institute of Technology, Kharagpur* *INDIA* [[alternative HTML version deleted]]