Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
973 views
in Technique[技术] by (71.8m points)

graphics - Basic R: move y-Axis for barplot

is there a way to move the y-Axis to the right, so that the gap between the y-Axis and the first bar is 0?

enter image description here

So far i've tried the axis() command to make a new y-Axis. But i always get the same one shown above.

Here is a sample of the dataset:

dat <- structure(list(Property = structure(c(269L, 169L, 355L, 41L, 
50L, 125L, 131L, 157L, 382L, 250L, 209L, 105L, 181L, 46L, 286L, 
12L, 179L, 85L, 69L, 17L), .Label = c("Aisha", "Aitik", "Aktogay", 
"Aktogay SX-EW", "Alex", "Aljustrel", "Alumbrera", "Amandelbult Section", 
"Amawusu", "Andina Division", "Anqing", "Antamina", "Antapaccay", 
"Antas", "Antucoya", "Aranzazu", "Ashele", "Asientos", "Atacocha", 
"Atlas Toledo", "Bafokeng-Rasimone", "Bagdad", "Bagdad SX-EW", 
"Bairen", "Baiyin Changtong", "Baiyin Shenbu", "Baiyunshan", 
"Bashkir", "Batu Hijau", "Bingham Canyon", "Bisha", "Bismark", 
"Bizhigou", "Black Mountain", "Boddington", "Boliden Area", "Bolivar", 
"Bozshakol", "Bozymchak", "Buenavista", "Buenavista SX-EW", "Buribayevsky", 
"Bystrinskoye", "Cadia East", "Candelaria", "Carlota", "Carmen de Andacollo", 
"Carmen de Andacollo SX-EW", "Caserones", "Caserones SX-EW", 
"Cayeli", "Centinela Oxide", "Centinela Sulfide", "Central Region", 
"Cerro Colorado", "Cerro Corona", "Cerro Lindo", "Cerro Verde", 
"Cerro Verde SX-EW", "Chambishi", "Changhong", "Chapada", "Charcas", 
"Chelopech", "Chibuluma South", "Chifeng Fubo", "Chimashan", 
"Chino", "Chino SX-EW", "Chungar", "Chuquicamata", "Chuquicamata SX-EW", 
"Cobar", "Cobriza", "Collahuasi", "Continental", "Copper Mountain", 
"Cozamin", "Cuajone", "Dahongshan", "Dajingzi", "Daluowan", "Dapingzhang", 
"Datong", "Deerni", "Deflector", "DeGrussa", "Dexing Complex", 
"Didipio", "Doe Run Mines", "Don Mario", "Dongguashan", "Dongjin", 
"Dongshengmiao", "Dongtong", "Duobaoshan", "Duobaoshan SXEW", 
"Eagle", "East Region Operations", "El Abra", "El Brocal", "El Porvenir", 
"El Soldado", "El Teniente", "El Teniente SX-EW", "El Valle", 
"Ellatzite", "Erdenet", "Ernest Henry", "Erzhulong", "Escondida", 
"Escondida SX-EW", "Etoile", "Fenghuangshan", "Fengjiashan", 
"Fengjiawan", "Fengshan", "Flin Flon", "Francisco I Madero", 
"Franke", "Frontier", "Fuyuan", "Gabriela Mistral", "Gaisky Complex", 
"Garpenberg", "Gibraltar", "Golden Grove", "Grasberg", "Guelb Moghrein", 
"Heijing", "Heiniudong", "Highland Valley", "Hongwei", "Huaron", 
"Huayu", "Hunchun", "Huogeqi", "Huzhan", "IMMSA", "Jabal Sayid", 
"Jaguar", "Jiama", "Jiangjushuijin", "Jilongshan", "Jinchuan", 
"Jingfeng", "Jinhongtao", "Jinshen", "Jiujiang", "Jixing", "Julcani", 
"Junpeng", "Kainantu", "Kalatongke", "Kamoto SX-EW", "Kansanshi", 
"Kansanshi SX-EW", "Kapan", "Karaganda Region", "Kazzinc Consolidated", 
"Kevitsa", "KGHM Polska Miedz", "Kidd Creek", "Kinsevere", "Konkola", 
"Kroondal", "Kylylahti", "La Caridad", "La Caridad SX-EW", "Lac des Iles", 
"Lalor Lake", "Lamazhaobei", "Langlike", "Langlois", "Langyashan", 
"Lanniping", "Laocun Hydrometallurgy Plant", "Laolaihong", "LaRonde", 
"Las Bambas", "Las Cruces", "Lianhuashan", "Liuzuo", "Liwan", 
"Liwu", "Lomas Bayas", "Long Complex", "Longteng", "Los Bronces", 
"Los Bronces SX-EW", "Los Pelambres", "Lubambe", "Lumwana", "Luodong", 
"Luojiahe", "Lvshui", "Manitoba Division", "Mantos Blancos", 
"Mantos Blancos SX-EW", "Maoyuan", "Maria", "Marikana", "Matagami", 
"MCSA Mining Complex", "Miami", "Milpillas", "Mimosa", "Minera Valle Central", 
"Miniere Musoshi Kinsenda", "Ministro Hales", "Minto", "Mission", 
"Modikwa", "Mogalakwena", "Morenci", "Morenci SX-EW", "Morococha", 
"Mototolo", "Mount Carlton", "Mount Milligan", "Mount Polley", 
"Mowana", "Mt Garnet", "Mt Isa Copper", "Mufulira", "Mufulira SX-EW", 
"Muliashi North", "Mutanda", "Mutanda SX-EW", "Myra Falls", "Nanchong", 
"Nchanga", "Nchanga SX-EW", "Nevada Operations", "Neves-Corvo", 
"New Afton", "Nifty", "Niutoushan", "Nkana", "Nkomati", "Norilsk", 
"Northparkes", "Nova-Bollinger", "Nuoergai", "Ok Tedi", "Olympic Dam", 
"Ontario Division", "Oyu Tolgoi", "Padcal", "Palabora", "Peak", 
"Phoenix SX-EW", "Phu Kham", "Pilanesberg", "Pinto Valley", "Pinto Valley SX-EW", 
"Prominent Hill", "Proyecto de Rio Tinto", "Pueblo Viejo", "Pulang", 
"Punitaqui", "Pyhasalmi", "Qiaoxiahala", "Qilianshan", "Quanli", 
"Quebrada Blanca", "Radomiro Tomic", "Raglan", "Raura", "Ray", 
"Ray SX-EW", "Red Chris", "Robinson", "Rosebery", "Ruashi", "Rubtsovskoye", 
"Rustenburg", "Sabinas", "Safford", "Saishitang", "Salobo", "Salvador", 
"San Francisco del Oro", "San Martin", "San Vicente", "Sanxin", 
"Sarcheshmeh", "Sepon Copper", "Shangrao", "Shaxi", "Shejiaao", 
"Shijiangjun", "Shijuli Copper Mine Liuhaogou", "Shilong", "Shitouzui", 
"Shizishan", "Shuangfo Conc. Plant", "Shuangfo Second Conc. Plant", 
"Shunqiang", "Sichuan La-La", "Sierra Gorda", "Sierrita", "Sierrita SX-EW", 
"Silver Bell", "Soerkuduke", "Songjiang", "Sossego", "Sotiel", 
"Spence SX-EW", "Stillwater", "Sudbury Operations", "Sunan Dongshanding", 
"Suolagou", "Suolajier", "Tangdan Conc. Plant", "Tangtang", "Tanyaokou", 
"Tayahua", "Telfer", "Tenke Fungurume", "Thalanga", "Tizapa", 
"Tongdan", "Tonghe", "Tongkuangyu", "Tonglvshan", "Tongshan", 
"Tongshankou", "Tongshanpai", "Toquepala", "Toquepala SX-EW", 
"Toromocho", "Trident - Sentinel", "Tritton", "Trojan", "Tulaergen", 
"Tuwu-Yandong", "Two Rivers", "Tyrone SX-EW", "Uchaly", "Union Section", 
"Unki", "Varvara", "Velardena", "Voisey's Bay", "Weilasituo", 
"Western Limb Tailings", "Wetar", "Wunugetushan", "Wushan", "Wutonghua", 
"Wutongjing", "Xietongmen", "Xiliduo", "Xinqiao", "Xinwang", 
"Yangla", "Yaodongzao", "Yauli", "Yauliyacu", "Yauricocha", "Yinan", 
"Yincan", "Yinlu", "Yinmin", "Yinshan", "Yinshanling", "Yiyang Xuri", 
"Yongping", "Yueshan", "Yulong", "Zaldivar", "Zarechensky", "Zhezkazgan Complex", 
"Zhibula", "Zhixincheng Conc. Plant", "Zhurihe", "Zihao", "Zijinshan", 
"Zijinshan SXEW", "Zimplats", "Zinkgruvan", "Zondereinde"), class = "factor"), 
    Country = structure(c(24L, 21L, 10L, 21L, 9L, 32L, 10L, 35L, 
    32L, 30L, 11L, 9L, 31L, 34L, 10L, 24L, 8L, 10L, 34L, 10L), .Label = c("Argentina", 
    "Armenia", "Australia", "Bolivia", "Botswana", "Brazil", 
    "Bulgaria", "Canada", "Chile", "China", "Dem. Rep. Congo", 
    "Dominican Republic", "Eritrea", "Finland", "Indonesia", 
    "Iran", "Kazakhstan", "Kyrgyzstan", "Laos", "Mauritania", 
    "Mexico", "Mongolia", "Papua New Guinea", "Peru", "Philippines", 
    "Poland", "Portugal", "Russia", "Saudi Arabia", "South Africa", 
    "Spain", "Sweden", "Turkey", "USA", "Zambia", "Zimbabwe"), class = "factor"), 
    Percent = c(0, 0, 0.15, 0.17, 0.69, 0.85, 0.86, 0.91, 1.34, 
    1.35, 1.6, 1.72, 1.73, 2.14, 2.16, 2.23, 4.71, 4.73, 4.79, 
    4.95), Tonnes = c(0.2, 26.4, 3.8, 89.3, 28.8, 0.6, 9.7, 73.9, 
    1.3, 44.4, 20.7, 2, 70.7, 3.2, 13.3, 429.9, 4.5, 9.7, 28, 
    43.2), Labor = c(0, 1.62, 7.97, 3.58, 8.29, 26.46, 10.42, 
    6.22, 25.42, 15.19, 16.44, 50.13, 28.65, 26.11, 13.42, 24.53, 
    47.08, 18.86, 14.07, 11.17), Energy = c(0, 4.5, 9.92, 7.89, 
    7.57, 7.07, 10.22, 5.49, 5.99, 9.08, 10.3, 8.53, 25.2, 7.48, 
    16.83, 10.17, 7.06, 15.44, 10.89, 13.83), Reagents = c(0, 
    15.33, 2.11, 29.11, 19.52, 2.21, 2.79, 22.37, 1.45, 4.78, 
    0.66, 9.31, 9.53, 33.36, 3.3, 4.75, 2.19, 1.26, 32.03, 0.94
    ), oOnsite = c(0, 5.13, 11.39, 12.71, 29.16, 20.88, 12.26, 
    27.06, 10.15, 17.63, 5.64, 9.89, 20.2, 13.3, 20.98, 12.44, 
    15.91, 14.77, 35.61, 11.6), Shipment = c(0, 2.27, 26.71, 
    2.27, 3.6, 17.21,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use axes as false and set them to pos zero

barplot(dat$TotalCC, dat$Tonnes, xaxt = "n", 
        axes = F,
        xlab="Paid Copper (000s Tonnes)",
        ylab = "Total Cash Costs (US cents/lb)", space = rep(0, 20), 
        main = "2018 Copper Production by Total Cash Cost", yaxs="i")
axis(1, pos=0)
axis(2, pos=0)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...