-1

I'm trying to plot some data in R as a simple line plot, (no dots, just a line connecting all the invisible points).

My script produces a Y-axis, but not an X-axis and I'm struggling to fix it, any help would be greatly appreciated.

I've tried changing xlim to various things, added the at option and played around with the width and the height, but it doesn't seem to work.

head(Truncmelt)
x <- Truncmelt [ ,1]
y <- Truncmelt [ ,2]
pdf(file = "Trunc.pdf", width = 25, height=7)
par(pch="0", col="white")
plot(y~x,  axes=FALSE, xlab = "Temperature", ylab = "CD")
axis(side=1, pos=-2, col="black", xlim=c(0,120))
axis(side=2, pos=0, col="black", at=-10:-20, ylim=c(10, 20))
lines(Truncmelt, col=("navy"))
box()
dev.off()

Ideally I'd like the plot to show an X axis from 0 to 120, though the data only run from 5 to 105 or so, but the X axis is never there.

Any help greatly appreciated,

Thank you

EDIT: Data included below.

Truncmelt <- data.frame(
  x = c(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, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95), 
  y = c(-12.4746, -12.5204, -12.5568, -12.8401, -12.585, -12.4484, 
    -12.1627, -12.4615, -12.3552, -12.7149, -12.6364, -12.2196, 
    -12.522, -12.5598, -12.6754, -12.5928, -12.3858, -12.8337, 
    -12.6562, -12.3757, -12.8435, -12.4136, -12.0363, -12.2963, 
    -12.5877, -12.2896, -12.1768, -12.2008, -12.2833, -12.1877, 
    -12.4883, -12.3077, -12.3134, -12.4816, -12.4651, -12.1372, 
    -12.5118, -12.1978, -12.2705, -12.3102, -11.9542, -11.8043, 
    -11.8192, -12.0839, -12.1434, -12.1661, -12.4645, -11.9337, 
    -11.9082, -11.6538, -12.0029, -11.9409, -12.203, -12.3232, 
    -11.9424, -12.1346, -11.9764, -11.6948, -12.1155, -12.2699, 
    -12.1826, -13.2273, -13.3182, -13.4455, -13.8004, -14.0562, 
    -14.1941, -14.5309, -14.394, -14.5556, -14.2982, -15.0219, 
    -15.319, -15.2574, -15.1451, -15.3356, -15.2799, -15.1584, 
    -15.3621, -15.1119, -15.2132, -15.3842, -15.2658, -14.9957, 
    -15.4742, -15.6432, -15.723, -15.3589, -15.598, -15.7019, 
    -15.5602))
MrFlick
  • 195,160
  • 17
  • 277
  • 295
Erik
  • 3
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Seems odd that you have `at=-10:-20` but your range doesn't cover negative values `ylim=c(10, 20)`. I don't think `xlim` and `ylim` are even parameters to `axis()` – MrFlick Oct 07 '19 at 18:01
  • 1
    Thank you for your pointers (as you can probably see I am very new to this), I I have corrected the y axis, but the problem persists with the x-axis. – Erik Oct 08 '19 at 07:59

1 Answers1

0

I'm not sure what you were trying to do with the pos= parameter, but a value of -2 causes the xaxis not to be drawn. And the xlim= and ylim= parameters need to be passed to plot().

plot(y~x, axes=FALSE, xlab = "Temperature", ylab = "CD", 
     xlim=c(0,120), ylim=c(-10, -20))
axis(side=1, col="black")
axis(side=2, col="black")
MrFlick
  • 195,160
  • 17
  • 277
  • 295