Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:54:05+00:00 2026-05-25T00:54:05+00:00

Apologies if I’m missing the obvious… I am plotting a 3d surface with rgl.

  • 0

Apologies if I’m missing the obvious…

I am plotting a 3d surface with rgl. My code is

library(rgl)
dem1 = read.table(file="file.txt",skip=5,header=F,na.strings="0.")
dem = dem1[order(dem1$V1,dem1$V2),] 
z = matrix(dem$V3,nrow=1250,ncol=1250)
is.na(z) = (z < 200)

#create x y dimensions
x=4*(1:nrow(z))
y=4*(1:ncol(z))

open3d()
bg3d("white")
persp3d(x,y,z)

which gives this map (the color was added to see the features better even though I didn’t put the code for it above)

enter image description here

The problem is that whatever I do to this map, it is upside down i.e. x should be y and what is currently y goes from west (0) to east (5000) but it should be the opposite such that the elevated feature should actually be bottom left rather than bottom right.

I plotted a very simple contour map using the same file with this script

dem=read.table("file.txt",header=F,skip=5,na.strings="0.")
library(lattice)
contourplot(dem$V3 ~ dem$V1+dem$V2)

which gives

enter image description here

and which gets the right axes and the most elevated region in the bottom left, exactly where it should be, so there is no problem with the data.

I explain how the data looks here and why I feel the need to reorder it with

dem = dem1[order(dem1$V1,dem1$V2),] 

The odd thing is whether I use the above command or not the 3d surface map looks exactly the same, which makes me wonder if the code is really using the “dem” dataset created with the order command or whether it is still using the original “dem1” data which it read from the file and which is in the wrong order.

I am very happy to send the data on request or to put it somewhere it can be seen but I can’t copy it here as it is 1250 rows x1250 columns.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:54:06+00:00Added an answer on May 25, 2026 at 12:54 am

    The problem is with the creation of z, the matrix of elevations. R fills matrices by columns when creating matrices. It is this filling by columns that is rearranging the elevations relative to one another. This is compounded by the fact that the matrix is square. If the matrix were not square, the relationship between x, y and z would have changed more markedly, instead of just being flipped.

    The solution is to have R fill the matrix by rows, e.g. define z using:

    z <- matrix(dem$V3, nrow=1250, ncol=1250, byrow = TRUE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if I'm missing something really obvious, but I'm trying to understand how to
Apologies for asking what's probably a very obvious question, I've been banging my head
Apologies if this has been answered previously. Say I have the following table: colA
Apologies for probably simple question, I've read the docs and still can't get this
Apologies in advance for the amount of code at the end, because there is
Apologies for not posting any code for this but all my efforts seem to
Apologies if this question has been asked already, but suppose we have this code
Apologies if this is trivial. I was trying to run this code - http://oreilly.com/pub/h/974#code
Apologies if the answer to this question is completely obvious but it has me
Apologies if any of what I'm about to say makes no sense or overlooks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.