Search code examples
rnetwork-programminglabelhistogramaxis-labels

Histogram x/y labels aren't displayed


I have uploaded a network on R and I have computed out-degree and in-degree centrality. Now, I would like to make two histograms with these elements using hist() but I cannot change x/y labels of the graph I do not know why! Who can help me? :)

This is the data:

structure(list(owner = c("ABBA JEANS MINING Sprl", "ABBA JEANS MINING Sprl", "ACACIA Sprl", "ACACIA Sprl", "ACACIA Sprl", "ACACIA Sprl", "AFRICAN ENGINEERING CORPORATE Sprl",  "AFRICAN ENGINEERING CORPORATE Sprl", "AFRICAN ENGINEERING CORPORATE Sprl",  "AFRICAN MINERALS (Barbados) Ltd Sprl"), armed_band = c("Mayi Mayi Militia (Bakata Katanga)",  "Militia (Elements)", "Batwa Ethnic Militia", "FDD", "Militia (Kamwina Nsapu)",  "RCD-Goma", "Anti-Balaka", "Kuluna Communal Militia", "Militia (Kamwina Nsapu)",  "Mayi Mayi Militia (Bakata Katanga)"), freq = c(1, 1, 1, 1, 4,  1, 1, 1, 1, 1)), row.names = c(NA, -10L), class = c("tbl_df",  "tbl", "data.frame"))

And this is the code I am using:

all_network=network(data_network,matrix.type="edgelist",directed=TRUE) 
InDegree <- degree(all_network, cmode="indegree")     
OutDegree <- degree(all_network, cmode="outdegree")   
par(mar = rep(2, 4))
par(mfrow=c(1,2)) 
hist(InDegree, 
 xlab="YYY", 
 main="Number", 
 ylab="Frequency", 
 col="grey",
 breaks = c(1*0:200),
 xlim = range(1:40),
 freq=FALSE, 
 )
hist(OutDegree, 
 main="XXX", 
 xlab='Number', 
 freq=FALSE, 
 ylab="Frequency", 
 col="lightblue",
 xlim = range(1:40),
 breaks = c(1*0:40),
 )
par(mfrow=c(1,1)) 

Thank you very much!


Solution

  • The margin you set are too small for labels to display.

    # This causes the problem
    par(mar = rep(2, 4))
    # Reset par to default
    dev.off()
    par(mar = c(5.1, 4.1, 4.1, 2.1))
    par(mfrow=c(1,2)) 
    hist(InDegree, 
         main="Number", 
          xlab="YYY", 
         
         ylab="Frequency", 
         col="grey",
         breaks = c(1*0:200),
         xlim = range(1:40),
         freq=T, 
    )
    
    
    hist(OutDegree, 
         main="XXX", 
         xlab='Number', 
         freq=T, 
         ylab="Frequency", 
         col="lightblue",
         xlim = range(1:40),
         breaks = c(1*0:40),
    )
    

    enter image description here