Unable to get date on X axis

data set

Date Auto Bank Fin_Ser FMCG IT Media Metal Pharma Private Bank PSU Banks Reality
01-Jan-20 8210.1 32102.9 14574.2 30234.25 15722.15 1794.2 2796.05 8047.1 17711.65 2526.4 297.85
02-Jan-20 8267.45 32443.85 14697.5 30266.2 15709.65 1800.65 2869.9 8053.95 17913.65 2576.7 301
03-Jan-20 8168.15 32069.25 14560.7 30109.25 15936.6 1760.5 2848.35 8111.95 17731.25 2524.3 299.65
06-Jan-20 7978.75 31237.15 14202.5 29799.3 15879.8 1717.35 2765.75 7987.35 17298.9 2414.65 292.4
07-Jan-20 8002.5 31399.4 14314.75 29861.8 15895.2 1735.15 2785.9 8036.5 17384.5 2416.65 298.05
08-Jan-20 7942.75 31373.65 14306.65 29893.2 15953.45 1726.6 2767.25 7996.15 17371.35 2401.85 297.05
09-Jan-20 8155.25 32092.4 14590.1 30123.6 15925.15 1767.95 2806.8 8033.15 17760.5 2459.85 305.15
10-Jan-20 8225.5 32097.4 14609.65 30370.45 15959.9 1770.65 2840.75 8058.5 17729.25 2461.4 310.65
13-Jan-20 8235.85 32177.65 14635.05 30713.45 16225.9 1784.8 2874.1 8078.45 17811.05 2468.7 317.15
14-Jan-20 8289.3 32071.65 14667.2 31145.4 16362.35 1822.2 2900.65 8117 17727.25 2462.35 316.75
15-Jan-20 8385.35 31824.9 14636.05 31237.1 16346.85 1837 2921.45 8166.2 17572.3 2463.3 320.9
16-Jan-20 8395.9 31853.9 14655.35 31338.2 16381.65 1863.5 2884.8 8203.1 17584.8 2465.8 323.8
17-Jan-20 8427.6 31590.65 14561.8 31371.45 16356.6 1870.1 2864.65 8345.3 17444.35 2451.85 324.15
20-Jan-20 8352.7 31080.65 14359.65 31426.75 16207.15 1835.7 2835.85 8269.35 17161.2 2414.9 325.8
21-Jan-20 8245.9 30947.55 14305.7 31145.95 16175.2 1876.5 2799.95 8274.2 17099.6 2412.8 321.15
22-Jan-20 8169.15 30701.45 14178.5 31153.15 16334.55 1909 2756.75 8256.65 16931.9 2410 320.85
23-Jan-20 8241.75 31004.05 14288.45 31226.9 16474.4 1871.85 2769.25 8300.2 17075.85 2437.9 327.65
24-Jan-20 8274.85 31241.75 14420.4 31474.9 16472.75 1889.9 2796.2 8294.05 17202.2 2446.3 328.65
27-Jan-20 8258.15 30837.4 14234.7 31149.7 16393.55 1882.45 2709.75 8416.35 17009.6 2391.25 326.8
28-Jan-20 8156.05 30761.4 14273.1 31027.05 16429.75 1861 2642.25 8420.25 16966.1 2370.65 326.95
29-Jan-20 8220.4 30877 14346.8 31426.25 16479.3 1868.05 2665.85 8412.8 17006.85 2378.15 328.5
30-Jan-20 8181.45 30647.4 14289.95 30936.45 16327.9 1845 2628.9 8237.05 16869.8 2346.75 327.15
31-Jan-20 8086.55 30833.6 14316.9 30775.3 16144.15 1835.3 2569 8138.6 16936.35 2366.05 331.05
01-Feb-20 7880.3 29820.9 13758.85 30196.65 16282.65 1755.9 2480.55 8013.75 16419.7 2277.95 305
03-Feb-20 7988.35 30023.25 13822.3 30435.3 16059.9 1779.2 2510.95 7967.55 16605.15 2221.85 310
04-Feb-20 8100.8 30686.7 14218.8 30744 16350.85 1782.2 2594.25 8122.4 16932.25 2241.15 318.6
05-Feb-20 8131.7 31001.95 14407.8 30934.4 16448.55 1764.7 2665.4 8125.6 17086.35 2252.4 326.4
06-Feb-20 8142.15 31304.05 14545.75 30736.6 16371.15 1792.35 2688.75 8227.9 17250.5 2316.05 326.25
07-Feb-20 8064.6 31201.95 14502.4 30809.5 16470.15 1827.25 2710.8 8341.85 17181.5 2313.2 320.3
10-Feb-20 7860.55 31058.15 14496.75 30528.45 16431.9 1798.1 2628.9 8261.25 17081.25 2290.45 317.1
11-Feb-20 7892.4 31300.6 14589.55 30414.55 16452.3 1827.45 2651.75 8324.65 17201.75 2293.4 317.8
12-Feb-20 7933.8 31492.9 14685.4 30986.25 16538.1 1824.2 2668.25 8265.05 17318.95 2249.25 315.2
13-Feb-20 7914.9 31230.25 14578.85 31039.3 16673.05 1834.85 2651.6 8335.7 17083 2256.3 313.8
14-Feb-20 7822.2 30834.8 14477.45 30646.75 16642.75 1832.5 2613.6 8331.7 16871.45 2211.2 310.3
17-Feb-20 7770.5 30680.7 14370.25 30481.05 16647.7 1812.25 2586.7 8204.85 16808.85 2145.65 305.7
18-Feb-20 7692.3 30562.5 14315.7 30360.6 16748.75 1845.9 2556.05 8198.3 16689.4 2128.2 302.85
19-Feb-20 7687.35 30838.2 14520.25 30835 16772.45 1882 2591.05 8378.65 16838.7 2147.55 306.2
20-Feb-20 7697.9 30942.85 14510.4 30636.25 16649.4 1871.7 2612.25 8364.35 16895 2168.95 306.25
24-Feb-20 7429.1 30455.1 14236.15 30147.6 16461.8 1829.6 2469.6 8115.55 16631.35 2109.2 299.75
25-Feb-20 7366 30432.7 14236.1 30173.2 16562.5 1817.25 2470.35 7938.45 16589.3 2109.6 302.55
26-Feb-20 7207.95 30306.85 14132.7 29965.55 16332.25 1803.9 2430 7839.2 16495.2 2096.6 297.5
27-Feb-20 7178.85 30187 14086.05 29981.2 16123.8 1760.55 2410.05 7885.15 16470.7 2049.1 290.3
28-Feb-20 6903.95 29147.15 13566.45 29310.25 15212.95 1670.7 2246.05 7576.75 15953.6 1945.6 280.55
02-Mar-20 6856.9 28868.4 13520 29138.9 15427.65 1594.7 2197.6 7535.1 15861.55 1857.6 279.65
03-Mar-20 6986.65 29177.05 13636.95 29406.2 15723.2 1647.65 2320.75 7920.6 16054.95 1881.2 284.15
04-Mar-20 6938.85 28653.7 13439.5 29223.75 15864.3 1617.65 2304.3 8086.55 15761.6 1865.9 281.05
05-Mar-20 6953.75 28815.35 13472.75 29530.5 15871.35 1606.3 2284.85 8146 15853.45 1891.9 277.85
06-Mar-20 6895 27801.45 13082.5 28937 15663.45 1527.15 2183.9 8018.3 15259.5 1794.8 269.75
09-Mar-20 6632.15 26462.6 12522.2 28056.5 14854.9 1425.6 2020.05 7756.45 14480.4 1688.35 260
11-Mar-20 6568.45 26487.8 12560.45 28078.75 14681.4 1454.3 1986.95 7623.05 14548 1635.95 255.25
12-Mar-20 6033.4 23971.15 11454.8 26083 13384.8 1304.15 1800.6 6942.55 13232.3 1420.65 230.3
13-Mar-20 6182 25166.45 12101.6 26208 13539.1 1282.35 1903.35 7268 13740.55 1573.25 235.85
16-Mar-20 5843.7 23101.15 11123.4 24707.65 12451.35 1226.05 1730.6 6959.35 12557.1 1497.4 216.15
17-Mar-20 5803.85 22155.15 10613.6 24929.85 12099.25 1153.15 1710.45 6979.1 12053.05 1490.35 211
18-Mar-20 5516.5 20580.2 9800.3 24186.5 11753 1141 1664.2 6705.75 11069.65 1480.5 197.75
19-Mar-20 5180.5 20083.5 9598.35 23970.75 11340 1086.9 1574.2 6655.5 10789.75 1438.85 191.2
20-Mar-20 5370.15 20317.6 9871.95 25931.6 12363.4 1128.95 1692.85 6951.9 10927.9 1463.45 196.4
23-Mar-20 4626.5 16917.65 8298.5 23184.05 11179.6 1015.4 1496.45 6432.3 8974.3 1277.75 174.1
24-Mar-20 4693.35 17107.3 8418.7 23935.3 11865.05 1031.7 1502.4 6611.05 9050.5 1305.35 170.65
25-Mar-20 4936.15 18481.05 9203.3 24471.7 12233.35 1055.45 1541.2 6695.55 9775.85 1327.55 175.1
26-Mar-20 5061.3 19613.9 9698.55 25680.1 12535.6 1067.5 1542.95 6775 10556.2 1335.15 185.8
27-Mar-20 4938.7 19969 9754.3 25740.45 12569.1 1055.4 1554.85 6813.05 10738.15 1339.65 185.05
30-Mar-20 4669.15 18782.4 9030.65 25831.55 12318.8 1021.85 1507.7 6896 10089.4 1295.45 171.6
31-Mar-20 4731.3 19144 9317.3 27319.2 12763.65 1039.95 1585.9 7176.5 10173.7 1324.85 175.5
01-Apr-20 4657.55 18208.35 8942.55 26358.8 12045.85 1001.25 1553.55 7026.7 9685.1 1283.1 172.1
03-Apr-20 4517.75 17249.3 8562.1 26537.75 11680.05 987.2 1522.9 7361.6 9157.1 1232.3 172.05
07-Apr-20 4951.55 19062.5 9278.3 28745.3 12588.95 1045.5 1637 8124.85 10169.4 1261.85 183
08-Apr-20 5043.6 18946.45 9243.45 28839.9 12491.55 1064.25 1624.85 8412.2 10158.4 1261.25 180.5
09-Apr-20 5568.45 19913.6 9803 28953.2 12728.55 1105.45 1705.45 8800.45 10695 1302.35 185.75
13-Apr-20 5432.1 19488 9500.65 28509.85 12603.1 1068.55 1738.4 9044.35 10500.9 1276.95 176.7
15-Apr-20 5333 19057.05 9239.35 29686.95 12702.6 1078.6 1752.9 9038.8 10278.95 1270.85 179.95
16-Apr-20 5394.15 19400 9392.6 29512.3 12463.6 1106.95 1779.75 9199.3 10442.65 1289 181.3
17-Apr-20 5668.9 20681.45 9905.55 29202.35 12649.25 1144.4 1816.5 9157.75 11212.1 1315.2 187.8
20-Apr-20 5591 20522.65 9930.65 28598.1 12847.65 1137.95 1756.45 9149.2 11082.9 1370.15 188.9
21-Apr-20 5294.05 19409.35 9468.8 28480.6 12408.85 1079.2 1666.6 9381.65 10430.7 1317.2 185.45
22-Apr-20 5426.85 19701.85 9569.2 29185.15 12571.3 1151 1673.3 9377 10580.65 1315.9 184.05
23-Apr-20 5464.75 20267.95 9808.95 28786.25 13128.2 1163.8 1694.75 9388.9 10915.55 1311.15 185.45
24-Apr-20 5377.25 19586.65 9431.85 28636.7 12816.2 1121.7 1645.2 9518.45 10542.6 1262.6 177.7
27-Apr-20 5433.2 20081.15 9627.6 29052.55 13121.15 1129.1 1666.6 9602.05 10857.55 1267.7 180.1
28-Apr-20 5447.1 20671.1 9951.2 28778.15 13133.65 1134.9 1661.65 9386.2 11243.55 1283.6 181.5
29-Apr-20 5543.75 21090.2 10292.9 28665 13424.95 1165.95 1723.8 9385.45 11455.7 1315.6 183.15
30-Apr-20 5901.4 21534.5 10570.8 28669.3 14108.35 1159.75 1859.9 9327.1 11743.45 1326.05 187.3

Thanks in advance!

You do not mention what function you are using to plot the data. Here are two examples using the base plot() function and ggplot(). I used a function from the lubridate package to change the first column into a date.

library(ggplot2)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
DF <- read.csv("c:/users/fjcc/Documents/R/Play/Dummy.csv", sep = "\t", 
               stringsAsFactors = FALSE)
DF$Date <- dmy(DF$Date)
plot(DF$Date, DF$Auto, type = "l")


ggplot(DF, aes(Date, Auto)) + geom_line()

Created on 2020-05-05 by the reprex package (v0.3.0)

1 Like

Thanks for the help,

I have used the following code to get this plot.
plot<- plot(data1$Auto,type = "l",col = "red", xlab = "Date", ylab = "NIFTY point", ylim = c(0,35000), lwd=3,
main = "NIFTY indices of different sector")
lines(data1$Bank, type = "l", col = "maroon", lwd=3)
lines(data1$Financial.Services, type = "l", col = "green", lwd=3)
lines(data1$FMCG, type = "l", col = "dark green", lwd=3)
lines(data1$IT, type = "l", col = "purple", lwd=3)
lines(data1$Media, type = "l", col = "yellow", lwd=3)
lines(data1$Metal, type = "l", col = "magenta", lwd=3)
lines(data1$Pharma, type = "l", col = "orange", lwd=3)
lines(data1$Private.Bank, type = "l", col = "cyan", lwd=3)
lines(data1$PSU.Bank, type = "l", col = "black", lwd=3)
lines(data1$Reality, type = "l", col = "blue", lwd=3)

using the data set shared above can yo please help me in making this type of plot with month on x axis and all 11 lines in the plot.

Thanks in advance.

Your calls to plot() and lines() do not have any x values. Notice that in my code I passed both the Date and the Auto column to plot(). Try this.

library(lubridate)
data1$Date <- dmy(data1$Date)
plot<- plot(data1$Date, data1$Auto,type = "l",col = "red", xlab = "Date", ylab = "NIFTY point", ylim = c(0,35000), lwd=3,
            main = "NIFTY indices of different sector")
lines(data1$Date, data1$Bank, type = "l", col = "maroon", lwd=3)
lines(data1$Date, data1$Financial.Services, type = "l", col = "green", lwd=3)
lines(data1$Date, data1$FMCG, type = "l", col = "dark green", lwd=3)
lines(data1$Date, data1$IT, type = "l", col = "purple", lwd=3)
lines(data1$Date, data1$Media, type = "l", col = "yellow", lwd=3)
lines(data1$Date, data1$Metal, type = "l", col = "magenta", lwd=3)
lines(data1$Date, data1$Pharma, type = "l", col = "orange", lwd=3)
lines(data1$Date, data1$Private.Bank, type = "l", col = "cyan", lwd=3)
lines(data1$Date, data1$PSU.Bank, type = "l", col = "black", lwd=3)
lines(data1$Date, data1$Reality, type = "l", col = "blue", lwd=3)
1 Like

thanks a lot for your help.

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