'How to display centroids for categorical variables instead of arrows using function ggord?
I really can’t figure out how to display just the centroids for my categorical variables using the function ggord. If anybody could help me, that would be great. Here is an example of what I’m trying to achieve using the dune data set:
library(vegan)
library (ggord)
library(ggplot2)
ord <- rda(dune~Moisture+ Management+A1,dune.env)
#first plot
plot(ord)
# second plot
ggord(ord)
#I tried to add the centroids, but somehow the whole plot seems to be differently scaled?
centroids<-ord$CCA$centroids
ggord(ord)+geom_point(aes(centroids[,1],centroids[,2]),pch=4,cex=5,col="black",data=as.data.frame(centroids))
In the first plot only the centroids (instead of arrows) for moisture and management are displayed. In the ggord plot every variable is displayed with an arrow.
And why do these plots look so different? The scales of the axes is totally different?
Solution 1:[1]
You can use forloop.first to check if the loop is executed first and then use an appropriate if tag to display the image. Please see the for loop related variables from the link below:
Ref: https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#for
{% if forloop.first %}
# Show first image here
{% endif %}
Solution 2:[2]
Try this:
<div style="background-image: url('{{properties.0.propertyimages_set.url}}'); background-size: 100% 100%;"; class="tm-row-featured">
<div class="featured-content">
<p><span>Name: </span>{{properties.0.property_name}}</p>
<hr>
<p><span>Type: </span>{{properties.0.property_type}}</p>
<p><span>Price: </span>₦{{properties.0.price}}</p>
<p><span>Location: </span>{{properties.0.property_state}}</p>
<p><a href="{% url 'property_details' properties.0.property_slug %}">More info >>></a></p>
</div>
</div>
Solution 3:[3]
The solutions above didnt work for me. I finally found a way around the solution thus:
{% for property in properties %}
<div
{% with property.propertyimages_set.all|first as photo %} style="background-image: url('{{photo.image.url}}'); background-size: 100% 100%; "
; {% endwith %}
class="tm-row-featured"
>
<div class="featured-content">
<p><span>Name: </span>{{property.property_name}}</p>
<hr>
<p><span>Type: </span>{{property.property_type}}</p>
<p><span>Price: </span>₦{{property.price}}</p>
<p><span>Location: </span>{{property.property_state}}</p>
<p><a href="{% url 'property_details' property.property_slug %}">More info >>></a></p>
</div>
</div>
{% endfor %}
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Syed Muhammad Dawoud Sheraz |
| Solution 2 | yousof |
| Solution 3 | prynet |
