2

My x-axis has values from 0 to about 150. It goes till 99 then starts 100 over the 1 and so on. please suggest some solution.

It is like 100 is showing over 1, 102 on 2 and so on. It is all congested.

structure(list(Runs = c(12, 37, 25, 54, 31, 2), Mins = c("33", 
"82", "40", "87", "45", "6"), BF = c("22", "67", "38", "66", 
"46", "2"), `4s` = c("1", "6", "4", "7", "3", "0"), `6s` = c("0", 
"0", "0", "0", "1", "0"), SR = c("54.54", "55.22", "65.78", "81.81", 
"67.39", "100"), Pos = c("2", "2", "1", "1", "1", "7"), Dismissal = c("lbw", 
"caught", "run out", "bowled", "lbw", "not out"), Inns = c("1", 
"2", "1", "1", "2", "1"), ...10 = c(NA, NA, NA, NA, NA, NA), 
    Opposition = c("v Sri Lanka", "v Sri Lanka", "v Sri Lanka", 
    "v Sri Lanka", "v Sri Lanka", "v Sri Lanka"), Ground = c("Dambulla", 
    "Dambulla", "Colombo (RPS)", "Colombo (RPS)", "Colombo (RPS)", 
    "Colombo (RPS)"), `Start DateAscending` = structure(c(1219017600, 
    1219190400, 1219536000, 1219795200, 1219968000, 1252886400
    ), tzone = "UTC", class = c("POSIXct", "POSIXt"))), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

Code:

> attach(virat)

> library(ggplot2)

> ggplot(virat,aes(x=BF,y=Runs))+geom_point()

https://i.stack.imgur.com/aIiiG.png

  • Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically after `set.seed(1)`), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jun 17 '20 at 17:39
  • Hi Nukul, welcome to StackOverflow, could you please share a little sample of your data. Type `dput(head(virat))` and paste the output in your question. By the way, your code should be formatted as code, use three backticks. – Alexis Jun 17 '20 at 17:41
  • @Alexis https://imgur.com/a/r71lert – Nukul Goyal Jun 17 '20 at 17:44
  • @r2evans I am a beginner. Don't understand what you are trying to say – Nukul Goyal Jun 17 '20 at 17:51
  • 2
    Thanks for the edit! Much clearer now. Your x-axis are not numbers, but you have accidentally read in your data as characters. You can convert them to numbers again by using `as.numeric()`, but it is better to fix the code you are using to read in the data (or perhaps you accidentally convert everything to character by using `cbind` or `matrix` or similar). – Axeman Jun 17 '20 at 17:54

1 Answers1

0

This should work:

library(tidyverse)
ggplot(virat,aes(x=as.numeric(BF),y=Runs))+geom_point()

Explanation: BF feature is a character, so I converted it into numeric with as.numeric inside aes.

Hope it helps.

Alexis
  • 2,104
  • 2
  • 19
  • 40